我尝试连接到网络套接字(详细信息:here)以从中获取信息。
正如您所见,我需要客户端IP地址等等,这是我目前所拥有的:
//client IP address
//is client behind something?
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
ipAddress = request.getRemoteAddr();
}
String socketAddress = "whois.nic.uk";
int socketPort = 1043;
Socket socket = new Socket(socketAddress, socketPort);
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.flush();
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
//for every domain loop
String singleDomain = "google.co.uk"; //just an example
//<hostname of client> <IP address of client> <domain to query><cr><lf>
String whoIs2 = ipAddress + " " + ipAddress + " " + singleDomain + "\r\n";
//convert message to bytes
byte[] whoIs2B = whoIs2.getBytes();
基本上我不确定如何将whoIs2B(字节版本发送到套接字,如果有意义的话)?然后我需要将字节响应更改为文本,这就是我需要的全部内容。
注意:不要介意尝试/捕获,因为我必须删除一些不必要的信息,以便更容易看到我问的问题。
答案 0 :(得分:0)