{"id":46,"date":"2015-11-07T03:58:07","date_gmt":"2015-11-07T03:58:07","guid":{"rendered":"http:\/\/www.beer.org\/beerblog\/?p=46"},"modified":"2016-12-23T18:29:26","modified_gmt":"2016-12-23T18:29:26","slug":"how-to-reboot-a-dlink-router-from-a-script","status":"publish","type":"post","link":"https:\/\/www.beer.org\/blog\/index.php\/2015\/11\/07\/how-to-reboot-a-dlink-router-from-a-script\/","title":{"rendered":"How to reboot a DLink router from a script"},"content":{"rendered":"<p>I have a Dlink DIR-615 that periodically drops its connection to the outside world. It appears to coincide with my wireless provider going down but the DLink never recovers. I don&#8217;t know why; but whatever.<\/p>\n<p>I was going to use a relay <a href=\"https:\/\/www.beer.org\/blog\/my-phrob-army.html\">Phrob<\/a> to just power cycle it but figured I&#8217;d explore doing a soft reboot since that appears to bring the connection back up. Because the HTTP foo is not strong within me, I searched and found <a href=\"http:\/\/www.wizardofthenet.com\/2014\/01\/15\/d-link-dir-655-apply-cgi\/\">this article<\/a> which gave me the basic steps required to login to a DLink and reboot it. It didn&#8217;t work and I didn&#8217;t need to append a &#8220;A&#8221; to the password; but after some futzing and looking at the POST headers in Google Chrome, I eventually reached this script that I put in cron:<\/p>\n<pre>#!\/bin\/sh\r\n# Check whether we can see google's DNS, if not, login to the router and reboot it.\r\nADDR=192.168.34.3\r\nADMIN_PASS=\"Zm9vCg==\"\r\n\r\nping() {\r\n        echo Pinging;\r\n        ping -q -c 1 -n 8.8.8.8 &gt;\/dev\/null &amp;&amp; exit 0\r\n}\r\n\r\nlogin() {\r\n        curl -o - -X POST -d \"html_response_page=login.asp&amp;login_name=YWRtaW4A&amp;login_pass=$ADMIN_PASS&amp;graph_id=5190c&amp;&amp;log_pass=$ADMIN_PASS&amp;graph_code=&amp;login=Login\" http:\/\/$ADDR\/login.cgi | grep index.asp\r\n}\r\n\r\nreboot() {\r\n        echo \"Rebooting ... \" ;\r\n        curl -X POST -d  \"html_response_page=reboot.asp\" http:\/\/$ADDR\/reboot.cgi\r\n}\r\n\r\nping || (login &amp;&amp; reboot)\r\n<\/pre>\n<p>In order to encode your $ADMIN_PASS, you need to:<\/p>\n<pre>$ echo -n MYPASSWORD | base64\r\n<\/pre>\n<p>The ADMIN_PASS=&#8221;Zm9vCg==&#8221; above is what you&#8217;d get if your admin password was &#8220;foo&#8221;.<\/p>\n<p>This works on my DIR-615, Hardware Version E3 and Firmware Version 5.10. Hope it helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have a Dlink DIR-615 that periodically drops its connection to the outside world. It appears to coincide with my wireless provider going down but the DLink never recovers. I don&#8217;t know why; but whatever. I was going to use a relay Phrob to just power cycle it but figured I&#8217;d explore doing a soft&#8230; <a class=\"moretag\" href=\"https:\/\/www.beer.org\/blog\/index.php\/2015\/11\/07\/how-to-reboot-a-dlink-router-from-a-script\/\">Continue reading &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,7],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-memotoself","category-tech-stuff"],"_links":{"self":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":1,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.beer.org\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}