Created
January 22, 2022 18:51
-
-
Save lukemetz/280c5f2a818bc20161cf93746ad29f60 to your computer and use it in GitHub Desktop.
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 subprocess | |
import time | |
import os | |
OUTPUT = os.path.expanduser("~/luke_output_network") | |
num_per_file = 1000 | |
try: | |
os.makedirs(OUTPUT) | |
except: | |
print("dir already exists. continuing") | |
def get_ping(): | |
batcmd="ping -c 1 google.com" | |
try: | |
result = subprocess.check_output(batcmd, shell=True) | |
return float(result.split("time=")[1].split(" ms")[0]) | |
except Exception as e: | |
print("Could not reach google.") | |
print(e) | |
try: | |
print(result) | |
except: | |
pass | |
return None | |
saves = [] | |
while True: | |
try: | |
result = get_ping() | |
t = time.time() | |
saves.append((str(t), str(result))) | |
if len(saves) > num_per_file: | |
path = os.path.join(OUTPUT, str(t)+".txt") | |
print("writing output", path) | |
with open(path, "w") as f: | |
f.write("\n".join([", ".join(x) for x in saves])) | |
saves = [] | |
except Exception as e: | |
print(">>> FaIL", e) | |
time.sleep(1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment