代码语言
.
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
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
端口扫描
作者:
Dezai.CN
/ 发布于
2011/8/31
/
461
#include "Scaner.h"</div> <div>//==================================================================================== int main(int argc,char* argv[]) { string HostIP; unsigned BeginPort,EndPort,LocalHostIP; int ret;</div> <div>struct TCPConThrParam TCPConParam; struct UDPThrParam UDPParam; struct TCPSYNThrParam TCPSynParam; struct TCPFINThrParam TCPFinParam; pthread_t ThreadID;</div> <div>char* pTcpCon = {"-c"}; // command for tcp connect scan char* pTcpSyn = {"-s"}; // command for tcp syn scan char* pTcpFin = {"-f"}; // command for tcp fin scan char* pUdp = {"-u"}; // command for udp scan char* pHelp = {"-h"}; // command for help</div> <div> //-----------------------Is param OK------------------------------- if (argc != 2) { cout<<"Parameter error !"<<endl; return -1; } <div>//-----------------------TCP connect Scan-------------------------- if (!strcmp(pHelp,argv[1])) { cout<<"Scaner: usage: [-h] --help information"<<endl; cout<<" [-c] --TCP connect scan"<<endl; cout<<" [-s] --TCP syn scan"<<endl; cout<<" [-f] --TCP fin scan"<<endl; cout<<" [-u] --UDP scan"<<endl; return 1; } <div> //--------------------Input IP address---------------------------- cout<<"Please input IP address of a Host:"; cin>>HostIP;</div> <div> if(inet_addr(&(HostIP[0])) == INADDR_NONE) { cout<<"IP address wrong!"<<endl; return -1; } //--------------------Input the range of port--------------------- cout<<"Please input the range of port..."<<endl; cout<<"Begin Port:"; cin>>BeginPort; cout<<"End Port:"; cin>>EndPort; if(IsPortOK(BeginPort,EndPort)) { cout<<"Scan Host "<<HostIP<<" port "<<BeginPort<<"~"<<EndPort<<" ..."<<endl; } else { cout<<"The range of port is wrong !"<<endl; return -1; } //----------------------Get Local Host IP------------------------- LocalHostIP = GetLocalHostIP(); //-----------------------Ping Scan Host--------------------------- if (Ping(HostIP,LocalHostIP) == false) { cout<<"Ping Host "<<HostIP<<" failed, stop scan it !"<<endl; return -1; } //-----------------------TCP connect Scan--------------------------- if (!strcmp(pTcpCon,argv[1])) { cout<<"Begin TCP connect scan..."<<endl; //create thread for TCP connect scan TCPConParam.HostIP = HostIP; TCPConParam.BeginPort = BeginPort; TCPConParam.EndPort = EndPort; ret = pthread_create(&ThreadID,NULL,Thread_TCPconnectScan,&TCPConParam); if (ret==-1) { cout<<"Can't create the TCP connect scan thread !"<<endl; return -1; } ret = pthread_join(ThreadID,NULL); if(ret != 0) { cout<<"call pthread_join function failed !"<<endl; return -1; } else { cout<<"TCP Connect Scan finished !"<<endl; return 0; } } //-----------------------TCP syn Scan--------------------------- if (!strcmp(pTcpSyn,argv[1])) { cout<<"Begin TCP SYN scan..."<<endl; //create thread for TCP SYN scan TCPSynParam.HostIP = HostIP; TCPSynParam.BeginPort = BeginPort; TCPSynParam.EndPort = EndPort; TCPSynParam.LocalHostIP = LocalHostIP; ret = pthread_create(&ThreadID,NULL,Thread_TCPSynScan,&TCPSynParam); if (ret==-1) { cout<<"Can't create the TCP SYN scan thread !"<<endl; return -1; } <div>ret = pthread_join(ThreadID,NULL); if(ret != 0) { cout<<"call pthread_join function failed !"<<endl; return -1; } else { cout<<"TCP SYN Scan finished !"<<endl; return 0; } } //-----------------------TCP fin Scan--------------------------- if (!strcmp(pTcpFin,argv[1])) { cout<<"Begin TCP FIN scan..."<<endl; //create thread for TCP FIN scan TCPFinParam.HostIP = HostIP; TCPFinParam.BeginPort = BeginPort; TCPFinParam.EndPort = EndPort; TCPFinParam.LocalHostIP = LocalHostIP; ret = pthread_create(&ThreadID,NULL,Thread_TCPFinScan,&TCPFinParam); if (ret==-1) { cout<<"Can't create the TCP FIN scan thread !"<<endl; return -1; } <div>ret = pthread_join(ThreadID,NULL); if(ret != 0) { cout<<"call pthread_join function failed !"<<endl; return -1; } else { cout<<"TCP FIN Scan finished !"<<endl; return 0; } } //-----------------------UDP Scan------------------------------- if (!strcmp(pUdp,argv[1])) { cout<<"Begin UDP scan..."<<endl; //create thread for UDP scan UDPParam.HostIP = HostIP; UDPParam.BeginPort = BeginPort; UDPParam.EndPort = EndPort; UDPParam.LocalHostIP = LocalHostIP; ret = pthread_create(&ThreadID,NULL,Thread_UDPScan,&UDPParam); if (ret==-1) { cout<<"Can't create the UDP scan thread !"<<endl; return -1; } <div>ret = pthread_join(ThreadID,NULL); if(ret != 0) { cout<<"call pthread_join function failed !"<<endl; return -1; } else { cout<<"UDP Scan finished !"<<endl; return 0; } } } <div></div>
试试其它关键字
端口扫描
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3