端口扫描技术与分析(四)

端口扫描分析(三)一个简单的扫描程序

来源/作者:Oliver

下面是一个端口扫描器的源程序,功能相当的简单,一个典型的TCPconnect()扫描。没有对返回的数据进行分析。

#include

#include

#include

#include

#include

#include

int main(intargc, char **argv)

{

intprobeport = 0;

structhostent *host;

int err, i,net;

structsockaddr_in sa;

if (argc !=2) {

printf("用法:%s hostname\n", argv[0]);

exit(1);

}

for (i = 1;i h_addr, sizeof sa.sin_addr);

else {

herror(argv[1]);

exit(2);

}

sa.sin_port= htons(i);

net =socket(AF_INET, SOCK_STREAM, 0);

if (net

#include

#include

#include"netdb.h"

structhostent *gethostbyaddr();

voidbad_addr();

main(argc,argv)

int argc;

char  *argv[];

{

char      addr[4];

int       i,j,

a0, a1, a2,a3,

c,

classB,classC, single, hex;

char      *fmt= "%d.%d.%d";

char      **ptr;

structhostent *host;

externchar   *optarg;

classB =classC = single = hex = 0;

while((c =getopt(argc,argv,"bcsx")) != EOF) {

switch(c) {

case 'b':

classB++;

break;

case 'c':

classC++;

break;

case 's':

single++;

break;

case 'x':

hex++;

break;

}

}

if(classB ==0 && classC == 0 && single == 0) {

fprintf(stderr,"usage: %s [-b||-c||-s] [-x] xxx.xxx[.xxx[.xxx]]\n", argv[0]);

exit(1);

}

if(classB)

if(hex) {

fmt ="%x.%x";

sscanf(argv[3],fmt, &a0, &a1);

} else {

fmt ="%d.%d";

sscanf(argv[2],fmt, &a0, &a1);

}

elseif(classC)

if(hex) {

fmt ="%x.%x.%x";

sscanf(argv[3],fmt, &a0, &a1, &a2);

} else {

fmt ="%d.%d.%d";

sscanf(argv[2],fmt, &a0, &a1, &a2);

}

elseif(single)

if(hex) {

fmt ="%x.%x.%x.%x";

sscanf(argv[3],fmt, &a0, &a1, &a2, &a3);

} else {

fmt ="%d.%d.%d.%d";

sscanf(argv[2],fmt, &a0, &a1, &a2, &a3);

}

sscanf(argv[1],fmt, &a0, &a1, &a2);

addr[0] =(unsigned char)a0;

addr[1] =(unsigned char)a1;

if(a0>255||a0255||a1%s\n", a0, a1, a2, a3, host->h_name);

ptr =host->h_aliases;

while (*ptr!= NULL) {

printf("%d.%d.%d.%d=> %s (alias)\n", a0, a1, a2, a3, *ptr);

ptr++;

}

}

if(single)

exit(0);

i++;

}

if(classC)

exit(0);

j++;

}

} elseif(classC) {

addr[2] =(unsigned char)a2;

if(a2>255||a2255||a2255||a3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值