当前位置: 技术问答>linux和unix
求LINUX下的端口扫描程序
来源: 互联网 发布时间:2016-07-20
本文导语: 使用Socket API,接受IP 地址,输出该IP 地址对应的主机所支持的 | 以前调试过一个,发个你看下吧。 其实道理不难,就是发送icmp包,跟ping类似,然后等待回应,若超时或者无响应则判断端口未开。 主机扫描的...
使用Socket API,接受IP 地址,输出该IP 地址对应的主机所支持的
|
以前调试过一个,发个你看下吧。
其实道理不难,就是发送icmp包,跟ping类似,然后等待回应,若超时或者无响应则判断端口未开。
主机扫描的也类似。
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/*#define CHKADDRESS( _saddr_)
{
u_char *p =(char *)&(_saddr_);
if( (p[0] == 10) || (p[0] ==168 &&16icmp_code!=ICMP_UNREACH_PORT) ||(port!=dstport))
{
if(count>10)
{
printf("port %d:icmp_type is %d;icmp_code is %d.n",port,icmp->icmp_type,icmp->icmp_code);
break;
}
if(ip->ip_src.s_addr==send_sa.sin_addr.s_addr && port==dstport)
{
//printf(" %d timesr",count);
count++;
break;
}
//printf("Not target icmp packet.continue check port %dn",dstport);
continue;
}
else
{
struct servent *se;
se=getservbyport(htons (dstport)," udp");
//if(se!=NULL)
printf("%5d %-20sn",dstport,(se==NULL)?"unkown":se->s_name);
}
break;
}
}
return EXIT_SUCCESS;
}
|
[root@RHEL4_U5 ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
getnameinfo failed
getnameinfo failed
tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:2341 ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 4 [ ] DGRAM 5684 /dev/log
unix 2 [ ACC ] STREAM LISTENING 5895 /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 6133 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 6106 /var/run/iiim/.iiimp-unix/9010
unix 2 [ ACC ] STREAM LISTENING 6169 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 6358 @/var/run/hal/hotplug_socket
unix 2 [ ] DGRAM 3840 @udevd
unix 2 [ ] DGRAM 14405
unix 3 [ ] STREAM CONNECTED 6357 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 6356
unix 3 [ ] STREAM CONNECTED 6177
unix 3 [ ] STREAM CONNECTED 6176
unix 2 [ ] DGRAM 6028
unix 3 [ ] STREAM CONNECTED 5795
unix 3 [ ] STREAM CONNECTED 5794
unix 2 [ ] DGRAM 5703
[root@RHEL4_U5 ~]#
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ftp *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
getnameinfo failed
getnameinfo failed
tcp 0 0 [UNKNOWN]:ssh [UNKNOWN]:2341 ESTABLISHED
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node Path
unix 4 [ ] DGRAM 5684 /dev/log
unix 2 [ ACC ] STREAM LISTENING 5895 /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 6133 /tmp/.font-unix/fs7100
unix 2 [ ACC ] STREAM LISTENING 6106 /var/run/iiim/.iiimp-unix/9010
unix 2 [ ACC ] STREAM LISTENING 6169 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 6358 @/var/run/hal/hotplug_socket
unix 2 [ ] DGRAM 3840 @udevd
unix 2 [ ] DGRAM 14405
unix 3 [ ] STREAM CONNECTED 6357 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 6356
unix 3 [ ] STREAM CONNECTED 6177
unix 3 [ ] STREAM CONNECTED 6176
unix 2 [ ] DGRAM 6028
unix 3 [ ] STREAM CONNECTED 5795
unix 3 [ ] STREAM CONNECTED 5794
unix 2 [ ] DGRAM 5703
[root@RHEL4_U5 ~]#
|
开源的 nmap ...