代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
多线程端口扫描
作者:
就一傻子
/ 发布于
2014/9/10
/
412
给定ip和端口范围,扫描开发的端口
package com.demo.net; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import java.util.concurrent.*; /** * User:superman * Date:2014/9/7 * Time:12:38 */ public class PortScanner { private int corePoolSize=50; private int maximumPoolSize=70; private long keepAliveTime=5000; private BlockingDeque<Runnable> workQueue=new LinkedBlockingDeque<Runnable>(); private ExecutorService threadPoolExecutor=new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime, TimeUnit.MILLISECONDS,workQueue); public void scan(String ip,int start,int end){ if(!validate(ip)){ System.err.println("Ip format is illegal."); return; } if(start<0||end>=(1<<16)){ System.err.println("The port number is illegal."); return; } InetAddress inetAddress=null; try { inetAddress = InetAddress.getByName(ip); if (!inetAddress.isReachable(5000)) { System.err.println(inetAddress.getHostAddress() + " is not reachable."); return; } } catch (IOException e) { // e.printStackTrace(); } for(int i=start;i<=end;i++){ while(workQueue.size()>maximumPoolSize){ try { // System.out.println("Thread queue is too long,sleep 500 milliseconds."); Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } threadPoolExecutor.execute(new ScanWorker(inetAddress, i)); } threadPoolExecutor.shutdown(); while (!threadPoolExecutor.isTerminated()) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("Done."); } private boolean validate(String ip){ if(ip==null||ip.length()==0) return false; String[] array=ip.split("\\."); if(array.length!=4) return false; for(String str:array){ try { int num=Integer.valueOf(str); } catch (NumberFormatException e) { return false; } } return true; } private class ScanWorker implements Runnable{ InetAddress inetAddress; int port; public ScanWorker(InetAddress inetAddress,int port){ this.inetAddress=inetAddress; this.port=port; } @Override public void run() { Socket socket = null; try { socket = new Socket(inetAddress, port); //socket.setSoTimeout(1000); String serviceName = getServiceName(socket.getPort()); System.out.println("Port:" + socket.getPort() + " ServiceName:" + serviceName + " Ip:" + inetAddress.getHostAddress()); } catch (IOException e) { // e.printStackTrace(); } finally { if (socket != null && !socket.isClosed()) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } private String getServiceName(int port) { String name ; switch (port) { case 21: name = "FTP"; break; case 23: name = "TELNET"; break; case 25: name = "SMTP"; break; case 80: name = "HTTP"; break; case 110: name = "POP"; break; case 135: name="RPC"; break; case 139: name = "netBIOS"; break; case 443: name = "HTTPS"; break; case 1433: name = "SQL server"; break; case 3389: name = "Terminal Service"; break; case 1521: name = "Oracle"; break; case 8080: name = "Tomcat"; break; default: name="Unknown"; } return name; } } public static void main(String[] args) { PortScanner portScanner=new PortScanner(); portScanner.scan("192.168.1.105",1,1000); // portScanner.scan("74.125.143.115",1,10000); } }
试试其它关键字
多线程
端口扫描
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
就一傻子
贡献的其它代码
(
4
)
.
将指定目录下的文件打成tar包
.
扫描一个网段内的可达ip
.
多线程端口扫描
.
mongodb 增删改查 工具类
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3