====================
[+]主机 192.168.1.102 在线.
[+]主机 192.168.1.103 在线.
[+]主机 192.168.1.111 在线.
[+]主机 192.168.1.114 在线.
[+]总共耗时33.5198891163秒.
二、端口扫描
1、TCP SYN端口扫描,不设置端口参数,则默认扫描1-1024端口
python scan.py --target 192.168.1.110-115 -s --SYN
[+]没有指定任何扫描端口,默认扫描1-1024
[!]扫描... 192.168.1.110
[!]扫描... 192.168.1.111
[!]扫描... 192.168.1.112
[!]扫描... 192.168.1.113
[!]扫描... 192.168.1.114
[!]扫描... 192.168.1.115
[+]正在处理扫描信息.
====================
[+]主机 192.168.1.111 开放的TCP端口有:[80]
[+]总共耗时165.125555992秒.
扫描指定端口:
python scan.py --target 192.168.1.1-254 -s --SYN --port 80 --timeout 1
[!]扫描... 192.168.1.1
[!]扫描... 192.168.1.2
[!]扫描... 192.168.1.3
[!]扫描... 192.168.1.4
...
[!]扫描... 192.168.1.253
[!]扫描... 192.168.1.254
[+]正在处理扫描信息.
====================
[+]主机 192.168.1.111 开放的TCP端口有:[80]
[+]主机 192.168.1.1 开放的TCP端口有:[80]
[+]总共耗时9.72222185135秒.
2、扫描UDP端口
python scan.py --target 192.168.1.1 -s --UPORT --timeout 1
[+]没有指定任何扫描端口,默认扫描1-1024
[!]扫描... 192.168.1.1
[+]正在处理扫描信息.
====================
[+]主机 192.168.1.1 开放的UDP端口有:[520]
[+]总共耗时27.4742250443秒.
也可同时进行发现扫描与端口扫描,如下:
python scan.py --target 192.168.1.1-254 -p --ARP -s --SYN --port 80 --timeout 1 --retry 2
[+]IP: 192.168.1.1 => MAC: 14:75:90:xx:xx:xx
[+]IP: 192.168.1.102 => MAC: 58:1f:28:xx:xx:xx
[+]IP: 192.168.1.114 => MAC: 6c:8d:c1:xx:xx:xx
[+]IP: 192.168.1.103 => MAC: 84:38:38:xx:xx:xx
[+]IP: 192.168.1.101 => MAC: 5c:f7:e6:xx:xx:xx
[!]扫描... 192.168.1.1
[!]扫描... 192.168.1.2
...
[!]扫描... 192.168.1.253
[!]扫描... 192.168.1.254
[+]正在处理扫描信息.
====================
[+]主机 192.168.1.1 开放的TCP端口有:[80]
[+]主机 192.168.1.111 开放的TCP端口有:[80]
[+]总共耗时45.2775988579秒.
OK,最后附上源码:
import argparse
import re
import time
import threading
from scapy.all import *
import logging
logging.getLogger('scapy.runtime').setLevel(logging.ERROR)
class Discovery_Scan(object):
'''
说明:用于发现扫描
'''
def __init__(self,args,timeout=0.5,retry=0):
self.targets = parse_target(args)
self.timeout = timeout
self.retry = retry
def arp_scan(self,pdst):
#ARP发现扫描
ans = sr1(ARP(pdst=pdst),timeout=self.timeout,retry=self.retry,verbose=False)
if ans:
if ans[ARP].op == 2: #操作码为2是is-at,是ARP响应
print '[+]IP: %s => MAC: %s' % (pdst,ans[ARP].hwsrc)
def icmp_scan(self,dst):
#ICMP发现扫描
ans = sr1(IP(dst=dst)/ICMP(),timeout=self.timeout,retry=self.retry,verbose=False)
if ans:
if ans[ICMP].type == 0: #ICMP type为0表示是ICMP echo-reply
print '[+]IP:主机%s echo-reply.' % dst
tcp_info = {}
def tcp_scan(self,dst,port):
#TCP SYN,发送TCP SYN包,有响应表示端口开放
ans,unans = sr(IP(dst=dst)/TCP(sport=RandShort(),dport=port,flags='S'),
timeout=self.timeout,retry=self.retry,verbose=False)
if ans.res:
if ans.res[0][0][IP].dst not in Discovery_Scan.tcp_info:
Discovery_Scan.tcp_info[ans.res[0][0][IP].dst] = True