Skip to content

Instantly share code, notes, and snippets.

@eguyd
Last active September 12, 2019 21:54
Show Gist options
  • Save eguyd/46cea929d472beefa619e2f9d5aaaf9b to your computer and use it in GitHub Desktop.
Save eguyd/46cea929d472beefa619e2f9d5aaaf9b to your computer and use it in GitHub Desktop.
Execute Ping Sweep from IDE console and output results to .txt file
"""
Program: Execute Ping Seep (ICMP Requests) and output results to a text file.
Interpreter Python 2.7 | Linux
"""
import os
import platform
from datetime import datetime
net = raw_input("Enter the IP address")
net1 = net.split('.')
a = '.'
net2 = net1[0] + a + net1[1] + a + net1[2] + a
st1 = int(raw_input("Enter the Starting Number "))
en1 = int(raw_input("Enter the Last Number "))
en1 = en1 + 1
oper = platform.system()
if oper == "Windows":
ping1 = "ping -n 1 "
elif oper == "Linux":
ping1 = "ping -c 1 "
else:
ping1 = "ping -c 1 "
t1 = datetime.now()
print "Scanning in Progress"
for ip in xrange(st1, en1):
addr = net2 + str(ip)
comm = ping1 + addr
response = os.popen(comm)
print response.readlines()
for item in response.readlines():
f = open('pingSweep.txt', 'a')
f.write(item)
f.close()
list1 = response.readlines()[:]
for line in list1:
if line.count("TTL"):
print "hello "
print addr, "--> Live"
break
t2 = datetime.now()
total = t2 - t1
print "scanning complete in ", total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment