Skip to content

Instantly share code, notes, and snippets.

@bascht
Created November 20, 2014 12:25
Show Gist options
  • Select an option

  • Save bascht/d8eeb53051178835b166 to your computer and use it in GitHub Desktop.

Select an option

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…
#!/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