当前位置 : 主页 > 编程语言 > c++ >

Socket扫描端口

来源:互联网 收集:自由互联 发布时间:2021-06-30
多线程与单线程 package hbfu.socket;import java.io.IOException;import java.net.Socket;import java.util.Scanner;public class Threadss implements Runnable{String ip;int port;int flag;public Threadss(String ip,int port){this.ip = ip;this
多线程与单线程
package hbfu.socket;

import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;

public class Threadss implements Runnable{
	String ip;
	int port;
	int flag;
	public Threadss(String ip,int port){
		this.ip = ip;
		this.port = port;
	}
	public void run(){
	
	try{
		Socket s = new Socket(ip ,port);
		System.out.println("Scannering"+80);
		s.close();
		System.out.println(ip+":open");
		flag = 1;
		}catch(IOException e){
			System.out.println(ip+":close");
		}
}
	}





package hbfu.socket;

import java.io.*;
import java.net.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.lang.*;

public class Socketss {
		public static void main(String [] args)throws UnknownHostException, IOException{
			int flag = 0;
			String ip = "";
			Scanner a = new Scanner(System.in);
			ip = a.nextLine();
			int Port = a.nextInt();
			for(int i = 0;i<=255;i++){
			String ips=ip+Integer.toString(i);
			new Thread(new Threadss(ips,Port)).start();
			}
      }
}
网友评论