网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  端口扫描程序java实现     
  文章作者:未知  文章来源:水木森林  
  查看:251次  录入:管理员--2007-11-17  
 
  怎么样扫描计算机系统本地和远程的端口,监测其是打开还是关闭的在很多应用程序中都要用到,下面是用java实现的简单的端口扫描程序。

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){}

}
}
 
 
上一篇: 电信网管中的java客户端(二)    下一篇: applet用http隧道技术和servlet通讯 (源码)
  相关文档
ejb 技术的数据库应用(2) 11-17
apache 1.3.14主要变化 11-17
一步一步学习midp2。0游戏编程(二) 11-17
演示matcher & pattern的用法 11-17
string和stringbuffer之概览 11-17
天极网 十四种java开发工具点评 11-17
decodeuricomponent 方法 11-16
jdk 1.6不支持amd 64 bit java plugin? 11-17
ajax学习基础:简单介绍数据岛使用方法 11-16
发布hibernate 3.1.1改进数据库支持 11-17
《精通soa:基于服务总线的struts+ejb+web service整合应用开发.. 11-17
java反射技术(二) 11-17
这肯定是他们的bug 11-17
java的复杂数据类型 11-16
利用threadlocal简化struts开发 11-17
java script与java applet综合运用(三) 11-16
SpringSide推荐的JDK5.0 feature 08-06
java servelet api入门之 servlet 慨述 11-17
java程序编码规范 11-17
在java中应用设计模式之singleton 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息