def main():
'''
@说明:扫描的主程序,首先根据条件创建Ping扫描或端口扫描对象,然后调用相关的扫描方法进行扫描。
'''
args = parse_opt()
if args.ping: #是否启动Ping扫描
if not args.timeout and not args.retry:
obj_ping = Discovery_Scan(args)
elif args.timeout and not args.retry:
obj_ping = Discovery_Scan(args,timeout=args.timeout)
elif not args.timeout and args.retry:
obj_ping = Discovery_Scan(args,retry=args.retry)
else:
obj_ping = Discovery_Scan(args,args.timeout,args.retry)
ip_list = obj_ping.targets[0]
if ip_list:
#ARP扫描
if args.ARP:
for pdst in ip_list:
t = threading.Thread(target=obj_ping.arp_scan,args=(pdst,))
t.start()
while threading.activeCount() != 1: #避免线程还没有运行完就提前输出不全的结果
time.sleep(1)
#ICMP扫描
elif args.ICMP:
for dst in ip_list:
t = threading.Thread(target=obj_ping.icmp_scan,args=(dst,))
t.start()
while threading.activeCount() != 1: #避免线程还没有运行完就提前输出不全的结果
time.sleep(1)
#TCP扫描
elif args.TCP:
port_list = [80,443,21,22,23,25,53,135,139,137,445,1158,1433,1521,3306,3389,7001,8000,8080,9090]
print '[+]请稍等,时间较长!'
for dst in ip_list:
print '[!]扫描...',dst
for port in port_list:
t = threading.Thread(target=obj_ping.tcp_scan,args=(dst,port))
t.start()
print '[+]正在处理扫描信息.'
while threading.activeCount() != 1: #避免线程还没有运行完就提前输出不全的结果
time.sleep(1)
if not obj_ping.tcp_info:
print '\n'
print '=' * 20
print '[+]未发现在线主机.'
else:
print '\n'
print '=' * 20
for ip_a in sorted(obj_ping.tcp_info.keys()):
print '[+]主机 %s 在线.' % ip_a
#UDP扫描
elif args.UDP:
port_list = [7,9.13,15,37,53,67,68,69,135,137,138,139,445,520]
print '[+]请稍等,时间较长!'
for dst in ip_list:
print '[!]扫描...',dst
for port in port_list:
t = threading.Thread(target=obj_ping.udp_scan,args=(dst,port))
t.start()