{"id":482,"date":"2010-10-01T03:00:11","date_gmt":"2010-10-01T03:00:11","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=482"},"modified":"2010-10-01T03:00:11","modified_gmt":"2010-10-01T03:00:11","slug":"%e5%be%97%e5%88%b0%e6%9c%ac%e6%9c%baip","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/01\/%e5%be%97%e5%88%b0%e6%9c%ac%e6%9c%baip\/","title":{"rendered":"\u5f97\u5230\u672c\u673aIP"},"content":{"rendered":"<pre lang=\"csharp\">\r\n1,   <body>  \r\n   <mce:script type=\"text\/javascript\"><!--  \r\n    function GetUrlText(url) {  \r\n       var xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\"); \/\/ http\u8bbf\u95ee  \r\n        try {  \r\n           xmlhttp.open(\"get\", url, false);  \r\n           xmlhttp.send();  \r\n            return xmlhttp.responseText;  \r\n        } catch (e) {  \r\n           return \"\";  \r\n      } finally {  \r\n           xmlhttp = null;  \r\n      }  \r\n  }  \r\n  var ip = GetUrlText(\"http:\/\/www.ip.cn\/getip.php?action=getip&ip_url=\").replace(\/^.*?(\\d+\\.\\d+\\.\\d+\\.\\d+).*$\/, \"$1\");  \r\n  alert(ip);  \r\n  \/\/ --><\/mce:script>  \r\n  <\/body> \r\n\r\n\r\n\r\n2,package com.tianren.service;\r\nimport java.net.*;\r\n\r\nimport sun.security.krb5.internal.HostAddress;\r\n\r\npublic class Test{\r\n InetAddress myIPaddress = null;\r\n InetAddress myServer = null;\r\n String hostAddress = null;\r\n String hostName = null;\r\n String Address = null ;\r\n String Name = null ;\r\n public static void main(String args[]) {\r\n\r\n  Test mytool;\r\n  mytool = new Test();\r\n  mytool.getAllServerIP();\r\n\/\/  System.out.println(\"Your host IP is: \" + mytool.getMyIP());\r\n\/\/  System.out.println(\"The Server IP is :\" + mytool.getServerIP());\r\n  \r\n  \r\n  \r\n }\r\n\r\n \/\/ \u53d6\u5f97LOCALHOST\u7684IP\u5730\u5740\r\n public String getMyIP() {\r\n  try {\r\n   myIPaddress = InetAddress.getLocalHost();\r\n   hostAddress = myIPaddress.getHostAddress();\/\/\u4ec5\u4ec5\u83b7\u5f97IP\u5730\u5740\r\n   hostName = myIPaddress.getHostName();\/\/\u83b7\u5f97\u672c\u5730\u540d\u79f0\r\n  } catch (UnknownHostException e) {\r\n  }\r\n  return (hostName);\r\n }\r\n\r\n \/\/ \u53d6\u5f97 www.abc.com \u7684IP\u5730\u5740\r\n public String getServerIP() {\r\n  try {\r\n   myServer = InetAddress.getByName(\"www.abc.com\");\r\n   Address = myServer.getHostAddress();\/\/\u83b7\u5f97www.abc.com\u7684ip\u5730\u5740\r\n   Name = myServer.getHostName();\/\/\u83b7\u5f97\u57df\u540d\r\n  } catch (UnknownHostException e) {\r\n  }\r\n  return (Name);\r\n }\r\n \/\/\u83b7\u53d6\u6b64\u57df\u540d\u4e0b\u7684\u6240\u6709IP\r\n public void getAllServerIP(){\r\n  String name = \"www.microsoft.com\";\r\n  try{\r\n   \r\n   InetAddress[] addresses= InetAddress.getAllByName(name);\r\n   for(int i =0;i<addresses.length;i++){\r\n    System.out.println(addresses[i].getHostAddress());\r\n   }\r\n  }catch(Exception e){\r\n   System.err.println(\"Unable to find: \"+name);\r\n\r\n  }\r\n }\r\n\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1, 2,package com.tianren.service; import java.net.*; im [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-14"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}