Skip to content

Instantly share code, notes, and snippets.

@mskf3000
Forked from mgeeky/pingsweep.py
Created September 26, 2020 03:20
Show Gist options
  • Select an option

  • Save mskf3000/bdf90080ec4ebb364b6ff4c87249b91a to your computer and use it in GitHub Desktop.

Select an option

Save mskf3000/bdf90080ec4ebb364b6ff4c87249b91a to your computer and use it in GitHub Desktop.
Quick Python Scapy-based ping-sweeper
#!/usr/bin/python
import sys
import netaddr
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import sr1, IP, ICMP
PING_TIMEOUT = 3
IFACE='eth0'
if __name__ == '__main__':
print '\tQuick Ping Sweep\n'
if len(sys.argv) != 2:
print '[?] Usage: pingsweep <network>'
sys.exit(0)
net = sys.argv[1]
print 'Input network:', net
responding = []
network = netaddr.IPNetwork(net)
for ip in network:
if ip == network.network or ip == network.broadcast:
continue
# Send & wait for response for the ICMP Echo Request packet
reply = sr1( IP(dst=str(ip)) / ICMP(), timeout=PING_TIMEOUT, iface=IFACE, verbose=0 )
if not reply:
continue
if int(reply.getlayer(ICMP).type) == 0 and int(reply.getlayer(ICMP).code) == 0:
print ip, ': Host is responding to ICMP Echo Requests.'
responding.append(ip)
print '[+] Spotted {} ICMP Echo Requests.'.format(len(responding))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment