4.1、工具简介
通过IP信息查询工具,我们可以获得目标主机的相关信息,可以进一步分析其资产,为后续渗透测试工作打下基础。
4.2、后端实现代码
package com.sducsrp.csrp.controller.ToolsController.IPInfo;
import com.alibaba.fastjson.JSONObject;
import com.sducsrp.csrp.common.Constants;
import com.sducsrp.csrp.common.Result;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
@RestController
public class IPInfoController {
@RequestMapping("tools/IPInfo")
public @ResponseBody
Result getIPInfo(@RequestParam("ip") String ip){
String url = "https://api.kinh.cc/IP/Speed/GetIPInfo.php?IP="+ip;
String return_json = sendRequest(url,"GET");
JSONObject jo = JSONObject.parseObject(return_json);
//for ip
String status = jo.get("status").toString();
String Info = jo.get("Info").toString();
// 解码(将Unicode还原为ASCII) org.apache.commons.lang.StringEscapeUtils#unescapeJava(String)
Info = StringEscapeUtils.unescapeJava(Info);
System.out.println(status+","+Info);
Result res=new Result(Constants.CODE_200,null,Info);
return res;
}
public String sendRequest(String urlParam,String requestType) {
HttpURLConnection con = null;
BufferedReader buffer = null;
StringBuffer resultBuffer = null;
try {
StringBuilder json = new StringBuilder();
URL url = new URL(urlParam);
//得到连接对象
con = (HttpURLConnection) url.openConnection();
//设置请求类型
con.setRequestMethod(requestType);
//设置请求需要返回的数据类型和字符集类型
//con.setRequestProperty("Content-Type", "text/plain; charset=utf-8");
con.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Safari/537.36 Edg/101.0.1210.32");
//允许写出
con.setDoOutput(true);
//允许读入
con.setDoInput(true);
//不使用缓存
con.setUseCaches(false);
//得到响应码
int responseCode = con.getResponseCode();
System.out.println(responseCode);
if(responseCode == HttpURLConnection.HTTP_OK){
//得到响应流
InputStream inputStream = con.getInputStream();
//将响应流转换成字符串
resultBuffer = new StringBuffer();
String line;
buffer = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
while ((line = buffer.readLine()) != null) {
//resultBuffer.append(line);
json.append(line);
}
return json.toString();
}
}catch(Exception e) {
e.printStackTrace();
}
return "{\"count\":0,\"data\":\"fail\n";
}
}
4.3、前端实现代码
<template>
<div style="margin-top: 100px">
<el-input v-model="ip" style="width: 250px;margin-right: 50px" placeholder="IP"></el-input>
<el-button @click="getIPInfo" type="primary">Query</el-button>
</div>
<el-card style="width: 40%;height: 500px;margin-left: 30%;margin-top: 5%">
<p>返回结果:</p>
<p>{{ myresult }}</p>
</el-card>
</template>
<script>
import request from "@/utils/request";
export default {
data(){
return{
ip:'',
myresult:''
}
},
methods:{
getIPInfo(){
request.get("/tools/IPInfo",{
params:{
ip:this.ip
}
}).then(res =>{
this.myresult=res.data
})
}
}
}
</script>