{"id":1346,"date":"2022-10-30T22:50:01","date_gmt":"2022-10-30T14:50:01","guid":{"rendered":"https:\/\/qaqaq.top\/?p=1346"},"modified":"2022-11-27T12:39:46","modified_gmt":"2022-11-27T04:39:46","slug":"io%e6%b5%81%e4%b8%8e%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b-%e7%bd%91%e7%bb%9c%e7%bc%96%e7%a8%8b%e6%a6%82%e8%bf%b0%e3%80%81ip%e7%9a%84%e7%90%86%e8%a7%a3%e4%b8%8einetaddress%e7%b1%bb%e7%9a%84%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=1346","title":{"rendered":"IO\u6d41\u4e0e\u7f51\u7edc\u7f16\u7a0b-\u7f51\u7edc\u7f16\u7a0b\u6982\u8ff0\u3001IP\u7684\u7406\u89e3\u4e0eInetAddress\u7c7b\u7684\u5b9e\u4f8b\u5316\u3001\u7aef\u53e3\u53f7\u7684\u7406\u89e3\u3001TCP\u548cUDP\u7f51\u7edc\u901a\u4fe1\u534f\u8bae\u7684\u5bf9\u6bd4"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P620;\r\n\r\nimport java.net.InetAddress;\r\nimport java.net.UnknownHostException;\r\n\r\n\/**\r\n * \u4e00\u3001\u7f51\u7edc\u7f16\u7a0b\u4e2d\u6709\u4e24\u4e2a\u4e3b\u8981\u7684\u95ee\u9898\uff1a\r\n * 1. \u5982\u4f55\u51c6\u786e\u5730\u5b9a\u4f4d\u7f51\u7edc\u4e0a\u4e00\u53f0\u6216\u591a\u53f0\u4e3b\u673a\uff1b\u5b9a\u4f4d\u4e3b\u673a\u4e0a\u7684\u7279\u5b9a\u7684\u5e94\u7528\r\n * 2. \u627e\u5230\u4e3b\u673a\u540e\u5982\u4f55\u53ef\u9760\u9ad8\u6548\u5730\u8fdb\u884c\u6570\u636e\u4f20\u8f93\r\n *\r\n * \u4e8c\u3001\u7f51\u7edc\u7f16\u7a0b\u4e2d\u7684\u4e24\u4e2a\u8981\u7d20\uff1a\r\n * 1. \u5bf9\u5e94\u95ee\u9898\u4e00\uff1aIP\u548c\u7aef\u53e3\u53f7\r\n * 2. \u5bf9\u5e94\u95ee\u9898\u4e8c\uff1a\u63d0\u4f9b\u7f51\u7edc\u901a\u4fe1\u534f\u8bae\uff1aTPC\/IP\u53c2\u8003\u6a21\u578b\uff08\u5e94\u7528\u5c42\u3001\u4f20\u8f93\u5c42\u3001\u7f51\u7edc\u5c42\u3001\u7269\u7406+\u6570\u636e\u94fe\u8def\u5c42\uff09\r\n *\r\n * \u4e09\u3001\u901a\u4fe1\u8981\u7d20\u4e00\uff1aIP\u548c\u7aef\u53e3\u53f7\r\n *\r\n * 1. \u552f\u4e00\u7684\u6807\u8bc6 Internet \u4e0a\u7684\u8ba1\u7b97\u673a\uff08\u901a\u4fe1\u5b9e\u4f53\uff09\r\n * 2. \u5728Java\u4e2d\u4f7f\u7528InetAddress\u7c7b\u4ee3\u8868IP\r\n * 3. IP\u5206\u7c7b\uff1aIPv4 \u548c IPv6\uff1b\u4e07\u7ef4\u7f51 \u548c \u5c40\u57df\u7f51\r\n * 4. \u57df\u540d\uff1a   www.baidu.com   www.mi.com  www.sina.com    www.jd.com\r\n *             www.vip.com\r\n * 5. \u672c\u5730\u56de\u8def\u5730\u5740\uff1a127.0.0.1  \u5bf9\u5e94\u7740\uff1alocalhost\r\n *\r\n * 6. \u5982\u4f55\u5b9e\u4f8b\u5316InetAddress: \u4e24\u4e2a\u65b9\u6cd5\uff1agetByName(String host)\u3001getLocalHost()\r\n *          \u4e24\u4e2a\u5e38\u7528\u65b9\u6cd5\uff1agetHostName() \/ getHostAddress()\r\n *\r\n * 7. \u7aef\u53e3\u53f7\uff1a\u6b63\u5728\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u7684\u8fdb\u7a0b\u3002\r\n *      \u8981\u6c42\uff1a\u4e0d\u540c\u7684\u8fdb\u7a0b\u6709\u4e0d\u540c\u7684\u7aef\u53e3\u53f7\r\n *      \u8303\u56f4\uff1a\u88ab\u89c4\u5b9a\u4e3a\u4e00\u4e2a 16 \u4f4d\u7684\u6574\u6570 0~65535\u3002\r\n *\r\n * 8. \u7aef\u53e3\u53f7\u4e0eIP\u5730\u5740\u7684\u7ec4\u5408\u5f97\u51fa\u4e00\u4e2a\u7f51\u7edc\u5957\u63a5\u5b57\uff1aSocket\r\n * @author RichieZhang\r\n * @create 2022-10-30 \u4e0b\u5348 9:51\r\n *\/\r\npublic class InetAddressTest {\r\n\r\n    public static void main(String&#91;] args) {\r\n\r\n        try {\r\n\r\n            \/\/File file = new File(\"hello.txt\");\r\n            InetAddress inet1 = InetAddress.getByName(\"192.168.10.14\");\r\n\r\n            System.out.println(inet1);\r\n\r\n            InetAddress inet2 = InetAddress.getByName(\"www.qaqaq.top\");\r\n            System.out.println(inet2);\r\n\r\n            InetAddress inet3 = InetAddress.getByName(\"127.0.0.1\");\r\n            System.out.println(inet3);\r\n\r\n            \/\/\u83b7\u53d6\u672c\u5730ip\r\n            InetAddress inet4 = InetAddress.getLocalHost();\r\n            System.out.println(inet4);\r\n\r\n            \/\/getHostName\r\n            System.out.println(inet2.getHostName());\r\n\r\n            \/\/getHostAddress\r\n            System.out.println(inet2.getHostAddress());\r\n\r\n        } catch (UnknownHostException e) {\r\n            e.printStackTrace();\r\n        }\r\n\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-1346","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1346"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1346"}],"version-history":[{"count":3,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1346\/revisions"}],"predecessor-version":[{"id":1351,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/1346\/revisions\/1351"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}