gpt4 book ai didi

java - 我是否必须写入套接字才能让服务器向我发送响应以读取某些服务的横幅?

转载 作者:太空宇宙 更新时间:2023-11-04 07:08:02 24 4
gpt4 key购买 nike

public class PortScan 
{

public String ip;

public PortScan(String ip)
{
this.ip = ip;
}
public void setIP( String ip )
{
this.ip = ip;
}

public String getIP()
{
return this.ip;
}
public void scan()
{
int i = 1;
String ip = this.getIP();
while(i < 50000)
{
try
{
Socket sock = new Socket(ip, i);
InputStream in = sock.getInputStream();
OutputStream out = sock.getOutputStream();
BufferedInputStream bins = new BufferedInputStream(in);
BufferedReader bin = new BufferedReader(new InputStreamReader(bins));
String response = bin.readLine();
System.out.println(response);
System.out.println(ip + ":" + i);
sock.close();
}
catch( UnknownHostException e )
{

//System.out.println("No host found.");
}
catch(IOException e)
{

//System.out.println("Problem connection to host.");
}
i++;
}
}
public static void main(String[] args)
{
PortScan aPortScan = new PortScan("127.1.1.1");

aPortScan.scan();
}
}

控制台输出:

SSH-2.0-OpenSSH_6.0p1 Debian-4
127.1.1.1:22<
null
127.1.1.1:80

最佳答案

是的,某些服务需要交互才能输出横幅。对于 HTTP 服务器,您必须发送 GET/HTTP/1.1,然后解析 Server: 行的响应。

关于java - 我是否必须写入套接字才能让服务器向我发送响应以读取某些服务的横幅?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21039228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com