Create High Speed Ping Scanning Script With Python
Create High Speed Ping Scanning Script With Python
Part I
[email protected]
www.bitforestinfo.com
Index
1. Overview ......................................... 03
Windows ................................. 06
Linux .................................. 06
Nmap .................................... 06
Function 1 .............................. 07
Function 2 .............................. 07
Function 3 .............................. 08
Function 4 .............................. 09
Features Of Script ...................... 09
8. Conclusion ........................................ 15
9. About Me .......................................... 16
Windows (built-in)
$ ping -n 5 192.168.1.101/24
Linux (built-in)
$ ping -c 5 192.168.1.101/24
You can use regular open source tool called Nmap. Best For
Scanning Because Nmap has also the ability to guess host even
after ICMP filter and Firewall. Type the following command to run
ICMP IP Scan:
$ nmap -sP -PI 192.168.1.101/24
Create Ping Sweep Script
# Extracting Ip Address
def IP_extractor(ip):
storeobj=[]
ip=ip.split(':')
x1=extraction(ip[0])
x2=extraction(ip[1])
x3=extraction(ip[2])
x4=extraction(ip[3])
for i1 in x1:
for i2 in x2:
for i3 in x3:
for i4 in x4:
storeobj.append("{}.{}.{}.{}".format(i1,i2,i3,i4))
return storeobj
4. This Function is For Using Multi-Processing In
Scanning.
Stable Script
Cross-platform Supported
#!/usr/bin/python
######################################################
By S.S.B Group
######################################################
Suraj Singh
Admin
S.S.B Group
[email protected]
http://bitforestinfo.blogspot.in/
# Importing Modules
import os, multiprocessing, time, optparse, platform
# Main Engine
class Pinger:
def __init__(self, target, thread, output, timeout):
self.timestarted=time.time()
self.live_ip_collector=multiprocessing.Queue()
self.target=target
self.thread=thread
self.output=output
self.timeout=timeout
self.set_os_command()
#self.checkping()
self.scanning_boosters()
# Saving OUtput
def save_output(self):
f=open(self.output,'a')
for i in self.live_ip_collector:
f.write(i+'\n')
f.close()
return
# Function For Multi_processing
def scanning_boosters(self):
proces=[]
for ip in self.target:
k=len(multiprocessing.active_children())
if k==self.thread:
time.sleep(3)
self.thread=self.thread+30
mythread=multiprocessing.Process(target=self.checkping, args=(ip,))
mythread.start()
proces.append(mythread)
# Printing Function
def showing_results(self):
storeip=[]
x=1
while x==1:
try:
storeip.append(self.live_ip_collector.get_nowait())
except:
x=x+1
self.live_ip_collector=storeip
print "\n"*3,"#"*80
print "[+] Scan Started On \t\t:\t",time.ctime(self.timestarted)
print "[+] Scan Closed On \t\t:\t",time.ctime(self.timeclose)
print "[+] Scan Total Duration \t:\t",self.timeclose-self.timestarted
print "[+] Total Live System Answered\t:\t",len(self.live_ip_collector)
if self.output:
self.save_output()
print "\n[+] Thanks For Using My Program. By S.S.B"
return
# Extracting Ip Address
def IP_extractor(ip):
storeobj=[]
ip=ip.split(':')
x1=extraction(ip[0])
x2=extraction(ip[1])
x3=extraction(ip[2])
x4=extraction(ip[3])
for i1 in x1:
for i2 in x2:
for i3 in x3:
for i4 in x4:
storeobj.append("{}.{}.{}.{}".format(i1,i2,i3,i4))
return storeobj
def main():
print __author__
parser=optparse.OptionParser(usage=usage,version=Version)
parser.add_option('-i','--target',type='string',dest='target',help="Specify IP
Addresses Range For Scan", default=None)
parser.add_option('-t',"--thread",type='string', dest="thread", help="Specify
Number of Thread For Scanning ", default='100')
parser.add_option('-o',"--output",type='string', dest="output", help="Specify
Path For Saving Output in Txt.", default="live_ip.txt")
parser.add_option('-c','--timeout',type='string', dest="timeout", help="Specify
No. Of Request Per IP",default='1')
(options, args)= parser.parse_args()
if not options.target:
print "[+] Please Provide IP Range. e.g: 192-192:128:1:4-70, For More, Check
Readme "
exit(0)
target=options.target
thread=options.thread
output=options.output
timeout=options.timeout
target=IP_extractor(target)
Pinger(target,thread,output,timeout)
return
# Trigger
if __name__ == '__main__':
main()
How To Use It
For Usages, Raw Script And More Info:
Usages Preview
Conclusion
Ping Sweeping is a very useful technique to find live hosts. With the help of multi-
processing module in python, we can boost various processes in the python script.
And Also, You Can Follow And Share My Blog And Github Account To Connect
With Our Bitforestinfo Audience And Also With Me.
About Me
Blog Introduction
"Python Is My Love,
Linux Is My Habit,
Web Scraping is my hobby,
C/C++ is my Interest, And,
Technology is my life "
I live in India,
You Can Follow Me On
Email [email protected]
Blog www.bitforestinfo.com
RSS Feed www.bitforestinfo.com/feeds/posts/default
Github github.com/surajsinghbisht054
Google+ plus.google.com//111795052270500977970
Facebook facebook.com/bitforestinfo/
Twitter twitter.com/bitforestinfo
Forum www.bitforestinfo.com/p/forum.html
Nice Day.