{"id":1411,"date":"2022-03-03T19:34:23","date_gmt":"2022-03-03T19:34:23","guid":{"rendered":"https:\/\/mdr.foobrdigital.com\/?p=1411"},"modified":"2022-03-03T19:34:23","modified_gmt":"2022-03-03T19:34:23","slug":"program-to-get-ip-address","status":"publish","type":"post","link":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/2022\/03\/03\/program-to-get-ip-address\/","title":{"rendered":"Program to get IP address"},"content":{"rendered":"\n<p>In this example we are gonna see how to get IP address of a System. The steps are as follows:<\/p>\n\n\n\n<p>1) Get the local host address by calling&nbsp;<code>getLocalHost()<\/code>&nbsp;method of InetAddress class.<br>2) Get the IP address by calling&nbsp;<code>getHostAddress()<\/code>&nbsp;method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import java.net.InetAddress;\n\nclass GetMyIPAddress\n{\n   public static void main(String args&#91;]) throws Exception\n   {\n      \/* public static InetAddress getLocalHost()\n       * throws UnknownHostException: Returns the address \n       * of the local host. This is achieved by retrieving \n       * the name of the host from the system, then resolving \n       * that name into an InetAddress. Note: The resolved \n       * address may be cached for a short period of time.\n       *\/\n      InetAddress myIP=InetAddress.getLocalHost();\n \n      \/* public String getHostAddress(): Returns the IP \n       * address string in textual presentation.\n       *\/\n      System.out.println(\"My IP Address is:\");\n      System.out.println(myIP.getHostAddress());\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>My IP Address is:\n115.242.7.243<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are gonna see how to get IP address of a System. The steps are as follows: 1) Get the local host address by calling&nbsp;getLocalHost()&nbsp;method of InetAddress class.2) Get the IP address by calling&nbsp;getHostAddress()&nbsp;method. Output:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[554],"tags":[],"_links":{"self":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1411"}],"collection":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/comments?post=1411"}],"version-history":[{"count":0,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/posts\/1411\/revisions"}],"wp:attachment":[{"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/media?parent=1411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/categories?post=1411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mudassirbackup.infinitycodestudio.com\/index.php\/wp-json\/wp\/v2\/tags?post=1411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}