{"id":984,"date":"2018-09-17T19:03:11","date_gmt":"2018-09-17T10:03:11","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=984"},"modified":"2018-12-23T01:50:22","modified_gmt":"2018-12-22T16:50:22","slug":"inetaddress-getbyname","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/en\/blog\/java\/inetaddress-getbyname","title":{"rendered":"Get hostname from Java IP address"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">Get hostname from Java IP address<\/a> <strong>InetAddress.getByName()<\/strong><\/h2>\n<p>\nspecified<strong>IP address<\/strong>have<strong>host name<\/strong>(in Japanese history)<strong>Machine name<\/strong>The following is a sample program to obtain the\n<\/p>\n<h2 class=\"common_title\"><a name=\"1\">sample program<\/a><\/h2>\n<pre class=\"sample_src\">\/**\r\n * Get hostname with the specified IP address.\r\n * @param address IP address\r\n * @return hostname\r\n * * If an unexpected exception occurs, the string \"UnknownHost\" is returned.\r\n *\/\r\npublic static String getHostName(String address) {\r\n    try {\r\n        InetAddress iaddress = InetAddress.getByName(address);\r\n        return iaddress.getHostName();\r\n    } catch (Exception e) {\r\n        e.printStackTrace(); }\r\n    }\r\n    return \"UnknownHost\"; }\r\n}\r\n<\/pre>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"2\">Execution Result<\/a><\/h2>\n<p>\u25c6Example of Execution<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) {\r\n    String name = getHostName(\"66.249.89.99\");\r\n    System.out.println(\"HostName = '\"+name+\"'\");\r\n}\r\n<\/pre>\n<p>\u25c6Output result<\/p>\n<pre class=\"console\">Hostname = 'jp-in-f99.google.com'\r\n<\/pre>","protected":false},"excerpt":{"rendered":"<p>Java Get hostname from IP address InetAddress.getByName() Specified IP address [\u2026]<\/p>","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":""},"categories":[19],"tags":[],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/984"}],"collection":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/comments?post=984"}],"version-history":[{"count":4,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/984\/revisions"}],"predecessor-version":[{"id":1869,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/posts\/984\/revisions\/1869"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/media?parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/categories?post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/en\/wp-json\/wp\/v2\/tags?post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}