⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 portscanner.java

📁 JSON(javascript) object creator and examples
💻 JAVA
字号:
import java.net.*;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PortScanner {
    
	public static void main(String[] args) {

        InetAddress ia=null;
        String host=null;
		String hostname=null;
		Socket s;
		int start=0, end=0;

		try
		{
			host = args[0];
			start = Integer.parseInt(args[1]);
			end = Integer.parseInt(args[2]);
		}
		catch (Exception e)
		{
			displayUsage();
			System.exit(1);
		}

		String str=".";
		String connected = "";

		try
		{
			ia = InetAddress.getByName(host);
			hostname = ia.getHostName();
		}
		catch (UnknownHostException e)
		{
             System.err.println(e );
			System.exit(1);
		}

        System.out.println("Scanning listening port:");
		for (int port = start; port < end; port++) 
		{
			try 
			{
				s = new Socket(host, port);
				connected += String.valueOf(port) + " ";
				s.close();
			}
            catch (IOException ex) 
			{
			}
			catch (Exception e) 
			{
				System.err.print(e.getMessage());
			}

			displayPercentage(start, end, port);

		} // for
        
		System.out.print("\n");

		System.out.println(connected);
		System.out.println("Scan finished.");
    }

	static void displayUsage() {
			System.out.println("Usage: java PortScanner <host> <port start> <port end>");
			System.out.println("Brian Lan Nov.25, 2008");
	}

	static void displayPercentage(int start, int end, int now)
	{
		int percentage = 0;
		String str;

		System.out.print("\r");
		switch (now % 4)
		{
			default:
			case 0: str = "-"; break;
			case 1: str = "\\"; break;
			case 2: str = "|"; break;
			case 3: str = "/"; break;
		}
		percentage = Math.round(100 * (now + 1 - start) / (end - start));
		System.out.print(str + " " + percentage + "% done");
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -