{"id":4593,"date":"2024-01-11T17:57:06","date_gmt":"2024-01-11T17:57:06","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4593"},"modified":"2024-01-11T17:58:22","modified_gmt":"2024-01-11T17:58:22","slug":"ip-functions","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/tcp-ip\/udp\/ip-functions","title":{"rendered":"IP functions"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Get local IP address for our adaptor<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>import socket\n\n#******************************************\n#******************************************\n#********** GET LOCAL IP ADDRESS **********\n#******************************************\n#******************************************\ndef get_local_ip():\n    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n\n    try:\n        sock.connect(('10.255.255.255', 1))     #Doesn't neeed to be a reachable IP address\n        local_ip = sock.getsockname()&#91;0]\n    except Exception:\n        local_ip = '127.0.0.1'\n    finally:\n        sock.close()\n\n    return local_ip<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Get local IP address for our adaptor<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[365],"tags":[],"class_list":["post-4593","post","type-post","status-publish","format-standard","hentry","category-udp"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4593","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4593"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4593\/revisions"}],"predecessor-version":[{"id":4595,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4593\/revisions\/4595"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}