Last active
May 23, 2017 06:44
-
-
Save ZacharyJacobCollins/ecdee17e8e992e8607f4423269afb1e3 to your computer and use it in GitHub Desktop.
python_ping_trace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create websites.txt, place in same directory as script. Fill with list of splitlines | |
# create empty file results.txt | |
# run python ping.py | |
import urllib2 | |
import subprocess | |
def readFile(): | |
array = [] | |
with open('./websites.txt') as file: | |
array = file.read().splitlines() | |
return array | |
def ping(website): | |
print "pinging: "+website | |
ping = subprocess.Popen(["ping", "-c", "1", website], stdout = subprocess.PIPE) | |
pingout, error = ping.communicate() | |
print pingout | |
return pingout | |
def trace(website): | |
print "tracing: "+website | |
trace = subprocess.Popen(['traceroute', website], stdout=subprocess.PIPE) | |
traceout = trace.communicate() | |
print traceout | |
return traceout; | |
def write_to_file(filepath, data): | |
file = open(r"./results.txt", "a+") | |
file.write(data + "\n") | |
file.close() | |
def execute(): | |
websites = readFile() | |
for website in websites: | |
write_to_file('./results.txt', ping(website)) | |
# write_to_file('./results.txt', trace(website)) | |
trace(website) | |
execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment