{"id":283,"date":"2015-10-22T15:00:42","date_gmt":"2015-10-22T23:00:42","guid":{"rendered":"http:\/\/www.skifactz.com\/wifi\/?p=283"},"modified":"2015-10-22T15:00:42","modified_gmt":"2015-10-22T23:00:42","slug":"log-internet-outages","status":"publish","type":"post","link":"https:\/\/www.skifactz.com\/wifi\/?p=283","title":{"rendered":"Log Internet Outages"},"content":{"rendered":"<p>My neighbor suspected he had daily Internet connectivity outages always taking place at the same time. I wrote this very simple Python script that pings Google.com at regular intervals and logs the\u00a0ping time and success\/failure. He was able to take this log to his ISP and escalate his tech support case with good evidence of technical problems.<\/p>\n<p>You can modify the script to ping your router instead of google.com i.e. 192.168.1.1 if you suspect local network problems.<\/p>\n<p><strong>Usage<\/strong><\/p>\n<p>From command line run .\/pinger.py [seconds] like: .\/pinger.py 120 to ping every two minutes. In Windows, with Python 2.x installed, you can also double click the icon and the script will ping once a minute.<\/p>\n<p>The script will save a .csv log in the same directory. You probably don&#8217;t want to ping at very short intervals for prolonged periods of time or it may be construed as a DoS attack by Google.<\/p>\n<p>Force quit the script after you have collected enough information. Otherwise it will loop forever.<\/p>\n<pre class=\"easycode; title: pinger.py;lang:;\"> #!\u00a0\/usr\/bin\/env\u00a0python\r\n#\u00a0Generates\u00a0ISP\u00a0connectivity\u00a0log\u00a0until\u00a0stopped\u00a0by\u00a0user.\r\n#\u00a0Version\u00a00.2.\u00a0www.skifatctz.com\/wifi\r\n\r\nfrom\u00a0datetime\u00a0import\u00a0datetime\r\nimport\u00a0time\r\nimport\u00a0os\r\nimport\u00a0sys\r\n\r\nhostname\u00a0=\u00a0\"google.com\"\r\nlogfile\u00a0=\u00a0open('pinglog.csv',\u00a0'w')\r\nlogfile.write('Test\u00a0of:\u00a0'\u00a0+\u00a0os.uname()[1])\r\nlogfile.close()\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\r\nif\u00a0len(sys.argv)\u00a0==\u00a01:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interval\u00a0=\u00a060\r\nelse:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0sys.argv[1].isdigit()\u00a0==\u00a0False:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sys.exit('Usage:\u00a0pinger.py\u00a0[x]\u00a0where\u00a0x\u00a0is\u00a0an\u00a0the\u00a0number\u00a0of\u00a0seconds\u00a0for\u00a0ping\u00a0interval.')\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interval\u00a0=\u00a0float(sys.argv[1])\r\n\r\nwhile\u00a01\u00a0==\u00a01:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logfile\u00a0=\u00a0open('pinglog.csv',\u00a0'a')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0todaysDate\u00a0=\u00a0str(datetime.now())[:10]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0currentTime\u00a0=\u00a0str(datetime.now())[11:-10]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0response\u00a0=\u00a0os.system(\"ping\u00a0-c\u00a01\u00a0\"\u00a0+\u00a0hostname)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0response\u00a0==\u00a00:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logfile.write(todaysDate\u00a0+','\u00a0+\u00a0currentTime\u00a0+\u00a0'\\n')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logfile.write(todaysDate\u00a0+','\u00a0+\u00a0currentTime\u00a0+\u00a0'\u00a0lost\u00a0connection'+\u00a0'\\n')\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print\u00a0hostname,\u00a0'lost\u00a0connection'\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logfile.close()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0time.sleep(interval)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My neighbor suspected he had daily Internet connectivity outages always taking place at the same time. I wrote this very simple Python script that pings Google.com at regular intervals and logs the\u00a0ping time and success\/failure. He was able to take this log to his ISP and escalate his tech support case with good evidence of &hellip; <a href=\"https:\/\/www.skifactz.com\/wifi\/?p=283\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Log Internet Outages<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,2],"tags":[],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-software","category-wifi"],"_links":{"self":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=283"}],"version-history":[{"count":1,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":284,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions\/284"}],"wp:attachment":[{"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skifactz.com\/wifi\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}