Skip to content

Instantly share code, notes, and snippets.

@thexavier666
Created June 25, 2017 16:59
Show Gist options
  • Save thexavier666/88a50c25316442eb293f0232a69250e7 to your computer and use it in GitHub Desktop.
Save thexavier666/88a50c25316442eb293f0232a69250e7 to your computer and use it in GitHub Desktop.
Checking if Intenet is working or not
import subprocess as sp
import time
def main():
sleep_dur = 5
test_website = 'stw.com'
cmd_timeout = '5'
cmd_positive_resp = 'HREF'
cmd_str = 'curl %s -m %s -s' % (test_website, cmd_timeout)
flag = 0
while flag == 0:
try:
cmd_out = sp.check_output(cmd_str, shell=True)
if cmd_out.find(cmd_positive_resp) != -1:
flag = 1
print '\n++++++++++++++++++++'
print 'Net is working!'
print '++++++++++++++++++++\n'
else:
print '\n=================='
print 'Waiting for net...'
print '==================\n'
except:
print '\n\nPress Ctrl+c once more...'
time.sleep(sleep_dur)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment