Created
April 6, 2018 10:14
-
-
Save DeviaVir/db7c4af575fc7088f86b364956f5df2e to your computer and use it in GitHub Desktop.
Quick snippet for checking network health of google.com (external) and wiki.xxxxxx.com (internal) to try and pinpoint when and to what extend network issues are occurring.
This file contains 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
import socket | |
import time | |
import datetime | |
def is_connected(remote_server): | |
try: | |
host = socket.gethostbyname(remote_server) | |
socket.create_connection((host, 80), 2) | |
return True | |
except socket.error: | |
pass | |
return False | |
def main(): | |
with open('/tmp/network_results.csv', 'w') as wr: | |
print('Date time,Google,Wiki\n') | |
wr.write('Date time,Google,Wiki\n') | |
while True: | |
time.sleep(1) | |
google = '0' | |
if is_connected('www.google.com'): | |
google = '1' | |
wiki = '0' | |
if is_connected('wiki.xxxxxx.com'): | |
wiki = '1' | |
date = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f%Z") | |
with open('/tmp/network_results.csv', 'a') as f: | |
print(','.join([date, google, wiki])) | |
f.write(','.join([date, google, wiki]) + '\n') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment