Created
November 20, 2014 12:25
-
-
Save bascht/d8eeb53051178835b166 to your computer and use it in GitHub Desktop.
Check if I am online. Useful for wonky interwebs like 3/4G or crappy office NAT…
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
| #!/usr/bin/env python | |
| # encoding:utf-8 | |
| import os | |
| import subprocess | |
| from time import sleep | |
| import curses | |
| PING = ["ping", "-q", "-c1", "8.8.8.8"] | |
| def green(string): | |
| return '\x1b[%sm%s\x1b[0m' % ('32;1', string) | |
| def red(string): | |
| return '\x1b[%sm%s\x1b[0m' % ('31;1', string) | |
| while(True): | |
| ok = (subprocess.call(PING, stdout = subprocess.PIPE) == 0) | |
| os.system('clear') | |
| if(ok): | |
| print green("ONLINE") | |
| else: | |
| print red("OFFLINE") | |
| sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment