{"id":4985,"date":"2025-12-17T20:55:45","date_gmt":"2025-12-17T20:55:45","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4985"},"modified":"2025-12-17T21:07:43","modified_gmt":"2025-12-17T21:07:43","slug":"get-ip-address","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/tcp-ip\/get-ip-address","title":{"rendered":"Get IP address"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import socket\n\n#******************************************\n#******************************************\n#********** GET LOCAL IP ADDRESS **********\n#******************************************\n#******************************************\n#ip_address = get_local_ip()\n#if ip:\n#    print(\"Connected to local network:\", ip_address)\n#else:\n#    print(\"No network connection\")\ndef get_local_ip():\n    try:\n        with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:\n            #Does not need to succeed; no packets sent\n            s.connect((\"8.8.8.8\", 80))\n            return s.getsockname()&#91;0]\n    except Exception:\n        return None\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[359],"tags":[],"class_list":["post-4985","post","type-post","status-publish","format-standard","hentry","category-tcp-ip"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4985"}],"version-history":[{"count":3,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4985\/revisions"}],"predecessor-version":[{"id":4990,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4985\/revisions\/4990"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}