国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 临海市| 金秀| 图木舒克市| 定结县| 宁强县| 福清市| 武威市| 朝阳市| 武穴市| 元朗区| 杨浦区| 合川市| 丘北县| 崇文区| 隆化县| 于田县| 商洛市| 大埔县| 桐庐县| 华坪县| 辽宁省| 昌宁县| 澳门| 南靖县| 南城县| 阿拉尔市| 肥城市| 屯昌县| 屏山县| 南陵县| 江陵县| 南漳县| 肇庆市| 丽水市| 石屏县| 嘉义县| 怀宁县| 九龙城区| 清河县| 武义县| 淮滨县|