{"id":79,"date":"2010-01-18T03:32:27","date_gmt":"2010-01-18T08:32:27","guid":{"rendered":"http:\/\/zitstif.no-ip.org\/?p=79"},"modified":"2010-01-18T03:51:34","modified_gmt":"2010-01-18T08:51:34","slug":"ipchicken-py","status":"publish","type":"post","link":"http:\/\/zitstif.no-ip.org\/?p=79","title":{"rendered":"ipchicken.py"},"content":{"rendered":"<p>If you are one of the very very few to remember a shell script that I wrote a while back that let&#8217;s you know your WAN IP address from the command line (<a title=\"http:\/\/zitstif.no-ip.org\/oldcrap\/scripts.html\" href=\"http:\/\/zitstif.no-ip.org\/oldcrap\/scripts.html\" target=\"_blank\">ipchicken<\/a>), I wrote a replacement for it in python. I hope this is useful to you:<\/p>\n<p><strong>ipchicken.py<\/strong><\/p>\n<pre lang=\"python\">#!\/usr\/bin\/env python\r\nimport re\r\nimport urllib\r\nimport socket\r\nimport sys\r\n\r\n#Test that ipchicken.com is up#\r\nvar = socket.socket()\r\ntry:\r\n        var.connect(('www.ipchicken.com', 80))\r\n        var.close()\r\nexcept socket.error:\r\n        var.close()\r\n        print \"www.iphicken.com seems to be down..\"\r\n        sys.exit(1)\r\n\r\nvar = urllib.urlopen('http:\/\/www.ipchicken.com')\r\nvar = str(var.readlines())\r\n\r\nreg = \"[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\"\r\n\r\nfor ip in re.findall(reg, var):\r\n        print \"\"\"Your WAN IP address is: %s \\nBrought to you by www.ipchicken.com\"\"\" % ip\r\nsys.exit(0)<\/pre>\n<p>Also, the beauty behind this, is that all you need is python and it should work on any operating system that supports python.<\/p>\n<p>Of course, if you have <strong>dog<\/strong> for Linux, then you can get the same affect with just a quick one liner:<\/p>\n<pre lang=\"bash\">dog http:\/\/www.ipchicken.com | egrep -wo \"[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\\.[[:digit:]]{1,3}\"\r\n<\/pre>\n<p>h<a title=\"http:\/\/www.google.com\/search?hl=en&amp;source=hp&amp;q=dog+is+better+than+cat+linux&amp;aq=f&amp;oq=&amp;aqi=\" href=\"http:\/\/www.google.com\/search?hl=en&amp;source=hp&amp;q=dog+is+better+than+cat+linux&amp;aq=f&amp;oq=&amp;aqi=\" target=\"_blank\">ttp:\/\/www.google.com\/search?hl=en&amp;source=hp&amp;q=dog+is+better+than+cat+linux&amp;aq=f&amp;oq=&amp;aqi=<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are one of the very very few to remember a shell script that I wrote a while back that let&#8217;s you know your WAN IP address from the command line (ipchicken), I wrote a replacement for it in python. I hope this is useful to you: ipchicken.py #!\/usr\/bin\/env python import re import urllib &hellip; <a href=\"http:\/\/zitstif.no-ip.org\/?p=79\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">ipchicken.py<\/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":[11,3],"tags":[12],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-code","category-posts","tag-ipchicken"],"_links":{"self":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=79"}],"version-history":[{"count":9,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":86,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=\/wp\/v2\/posts\/79\/revisions\/86"}],"wp:attachment":[{"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zitstif.no-ip.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}