207. 課程表
阿新 • • 發佈:2021-10-09
IP地址:inetAddress
- 唯一定位一臺網路上計算機
- 127.0.0.1:本機 localhost
- ip地址的分類
- ipv4/ipv6
- IPV4 127.0.0.1 4個位元組組成,0-255,42億;30億在北美,亞洲4億,2011年就用盡;
- IPV6 128位,8個無符號整數,abcde
-
2001:0bbc:2dc5:4526:4512:2663:4521:4562
-
- 公網-私網
- ABCD
- 192.168.xx.xx 專門給組織內部使用的
- 域名:記憶IP問題
- ip類
- ipv4/ipv6
package com.wzz.A04網路程式設計; import java.net.InetAddress; import java.net.UnknownHostException; //測試IP public class B01TestInetAddress { public static void main(String[] args) { try { //查詢本機地址 InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1"); System.out.println(inetAddress1); InetAddress inetAddress3 = InetAddress.getByName("localhost"); System.out.println(inetAddress3); InetAddress inetAddress4 = InetAddress.getLocalHost(); System.out.println(inetAddress4); InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");//查詢網站ip地址 System.out.println(inetAddress2); //常用方法 System.out.println(inetAddress2.getHostAddress());//ip System.out.println(inetAddress2.getHostName());//域名,或者自己電腦的名字 } catch (UnknownHostException e) { e.printStackTrace(); } } }