?? tcpthread.java.bak
字號:
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TCPThread extends Thread{
public static InetAddress hostAddress;
//最小的端口號
public static int MIN_port;
//最大的端口號
public static int MAX_port;
//線程總數
private int threadnum;
//查詢方式:0為ip;1為主機名
public static int type;
//ip地址前3位
public static int ip1;
//ip地址4~6位
public static int ip2;
//ip地址7~9位
public static int ip3;
//起始ip地址的最后4位
public static int ipstart;
//結束ip地址的最后4位
public static int ipend;
//完整的ip地址
public static String ipAll;
//掃描的主機名稱或ip
String hostname = "";
//端口的類別
String porttype = "0";
/*
*構造函數
*/
public TCPThread(String name,int threadnum){
super(name);
this.threadnum = threadnum;
}
/*
*運行函數
*/
public void run() {
//ip地址
int h = 0;
//端口號
int i = 0;
Socket theTCPsocket;
//根據ip地址進行掃描
if(type == 0){
//ip地址循環掃描
for(h = ipstart; h <=ipend; h++){
//組成完整的ip地址
ipAll = "" + ip1 + "." + ip2 + "." + ip3 + "." + h;
hostname = ipAll;
try{
//在給定主機名的情況下確定主機的 IP 地址
hostAddress=InetAddress.getByName(ipAll);
}
catch(UnknownHostException e){
}
//不同的端口循環掃描
for (i = MIN_port+threadnum; i < MAX_port + Integer.parseInt(ThreadScan.maxThread.getText()); i += Integer.parseInt(ThreadScan.maxThread.getText())){
try{
theTCPsocket=new Socket(hostAddress,i);
theTCPsocket.close();
ThreadScan.Result.append(hostname+":"+i);
//判斷端口的類別
switch(i){
case 21:
porttype = "(FTP)";
break;
case 23:
porttype = "(TELNET)";
break;
case 25:
porttype = "(SMTP)";
break;
case 80:
porttype = "(HTTP)";
break;
case 110:
porttype = "(POP)";
break;
case 139:
porttype = "(netBIOS)";
break;
case 1433:
porttype = "(SQL Server)";
break;
case 3389:
porttype = "(Terminal Service)";
break;
case 443:
porttype = "(HTTPS)";
break;
case 1521:
porttype = "(Oracle)";
break;
}
//端口沒有特定類別
if(porttype.equals("0")){
ThreadScan.Result.append("\n");
}
else{
ThreadScan.Result.append(":"+porttype+"\n");
}
}
catch (IOException e){
}
}
}
//掃描完成后,顯示掃描完成,并將“確定”按鈕設置為可用
if (i==MAX_port+Integer.parseInt(ThreadScan.maxThread.getText())){
ThreadScan.Result.append("\n"+"掃描完成...");
//將"確定"按鈕設置成為可用
if(!ThreadScan.Submit.isEnabled()){
ThreadScan.Submit.setEnabled(true);
}
}
}
//按照主機名進行端口掃描
if(type == 1){
for (i = MIN_port+threadnum; i < MAX_port+Integer.parseInt(ThreadScan.maxThread.getText()); i += Integer.parseInt(ThreadScan.maxThread.getText())){
try{
theTCPsocket=new Socket(hostAddress,i);
theTCPsocket.close();
ThreadScan.Result.append(" "+i);
switch(i){
case 21:
porttype = "(FTP)";
break;
case 23:
porttype = "(TELNET)";
break;
case 25:
porttype = "(SMTP)";
break;
case 80:
porttype = "(HTTP)";
break;
case 110:
porttype = "(POP)";
break;
case 139:
porttype = "(netBIOS)";
break;
case 1433:
porttype = "(SQL Server)";
break;
case 3389:
porttype = "(Terminal Service)";
break;
case 443:
porttype = "(HTTPS)";
break;
case 1521:
porttype = "(Oracle)";
break;
}
//端口沒有特定類別
if(porttype.equals("0")){
ThreadScan.Result.append("\n");
}
else{
ThreadScan.Result.append(":"+porttype+"\n");
}
}
catch (IOException e){
}
}
//掃描完成后,顯示掃描完成,并將“確定”按鈕設置為可用
if (i==MAX_port+Integer.parseInt(ThreadScan.maxThread.getText())){
ThreadScan.Result.append("\n"+"掃描完成...");
//將"確定"按鈕設置成為可用
if(!ThreadScan.Submit.isEnabled()){
ThreadScan.Submit.setEnabled(true);
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -