Skip to content

Instantly share code, notes, and snippets.

@powerexploit
Created October 9, 2019 17:19
Show Gist options
  • Save powerexploit/158606d8c60827abbeca86880d2e020c to your computer and use it in GitHub Desktop.
Save powerexploit/158606d8c60827abbeca86880d2e020c to your computer and use it in GitHub Desktop.
pingscanner using python
#!/usr/bin/python3
#pingscanner.py
import sys
from scapy.all import *
ip = sys.argv[1] # command line argument
icmp = IP(dst=ip)/ICMP()
#icmp = IP(dst=ip)/TCP()
#IP defines the protocol for IP addresses
#dst is the destination IP address
#TCP defines the protocol for the ports
resp = sr1(icmp,timeout=10)
if resp == None:
print("This host is down")
else:
print("This host is up")
@rudyryk
Copy link

rudyryk commented Oct 15, 2019

Hello, Ankit! Good positng, thank you. Btw, it's more general to write resp is None because None is a singleton. Also explicit imports are more preferred (in PEP-8) like from scapy.all import IP, ICMP, sr1

@powerexploit
Copy link
Author

powerexploit commented Oct 27, 2019

Hello, Ankit! Good positng, thank you. Btw, it's more general to write resp is None because None is a singleton. Also explicit imports are more preferred (in PEP-8) like from scapy.all import IP, ICMP, sr1

hey @rudyryk sorry for late reply but its same as
from scapy.all import * but i appreciate your response! I will be aware in next time

@srikantavaibhav
Copy link

Hello! Why do I get this error on running?
PermissionError: [Errno 1] Operation not permitted

How do I resolve it?

@powerexploit
Copy link
Author

Hello! Why do I get this error on running?
PermissionError: [Errno 1] Operation not permitted

How do I resolve it?

run script as root.
if you are using Ubuntu run it as :
sudo python3 pingscanner.py 192.168.x.x.

@rharix19
Copy link

How to run this script without root/sudo permission?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment