国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

端口掃描程序java實現(xiàn)

2019-11-18 13:53:02
字體:
供稿:網(wǎng)友

  怎么樣掃描計算機系統(tǒng)本地和遠程的端口,監(jiān)測其是打開還是關(guān)閉的在很多應(yīng)用程序中都要用到,下面是用java實現(xiàn)的簡單的端口掃描程序。

Source Code:



--------------------------------------------------------------------------------


/*
* Created on 2005-3-22
*
* TODO To change the template for this generated file go to
* Window - PReferences - Java - Code Style - Code Templates
*/

/**
* @author whandey connect to me: whandey@163.com
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
import java.io.*;
import java.net.*;
import java.util.*;


public class SocketPort {

public static void main(String[] args) {

String ip = "159.162.39.27";
String hostname = new String();

try{ //get the target ip address and hostname
InetAddress address = InetAddress.getByName(ip);
System.out.println(address);
hostname = address.getHostName();
System.out.println(hostname);
}
catch(UnknownHostException e)
{
System.out.println("Could not find "+ ip);

}


try
{ // creat the output file
PrintWriter fout = new PrintWriter( new FileWriter("PortInf.txt"));
fout.println("Information Of The Port On the " + hostname +"computer ");
fout.println();

// do ports scan
for(int nport = 25;nport < 30;++nport)
{
try
{

Socket s = new Socket(hostname,nport);
fout.println("The port " + nport + " is open!");

fout.println("Connected to "+ s.getInetAddress() + " on port " + s.getPort() + " from port "+ s.getLocalPort() + " of " + s.getLocalAddress());
//print the connected socket information
}

catch(IOException e)
{
fout.println("The port " + nport + " is closed!");
}

}
fout.close();

}
catch(IOException e){}

}
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 林周县| 资中县| 东阿县| 迁西县| 黔西| 方正县| 新郑市| 嘉善县| 淄博市| 乐陵市| 友谊县| 福海县| 凌源市| 资中县| 民乐县| 彭阳县| 胶南市| 革吉县| 喜德县| 梨树县| 辰溪县| 肃南| 阿坝| 伊宁市| 永平县| 景洪市| 关岭| 麻栗坡县| 资兴市| 宁化县| 吴桥县| 呼伦贝尔市| 沐川县| 白山市| 平舆县| 青海省| 长治县| 乌鲁木齐市| 青川县| 甘肃省| 宁强县|