Nội dung text Complete-Note-NP.pdf
Ch.4 Internet Addresses Unit-2 Network Programming Er.Sital Prasad Mandal bcanepaltu.com1
Internet Addresses • IP (Internet Protocol) Addresses – IPv4 (4 Bytes): dotted quad format • www.csie.nuk.edu.tw 140.127.208.17 – IPv6 (16 Bytes): 8 blocks of 4 hexadecimal digits separated by colons • www.csie.nuk.edu.tw ::ffff:8c7f:d011 • 2400:cb00:2048:0001:0000:0000:6ca2:c665 → 2400:cb00:2048:1::6ca2:c665 – Mixed: last 4 bytes of the IPv6 written as an IPv4 dotted quad address • www.nuk.edu.tw ::ffff:140.127.208.17 • FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 FEDC:BA98:7654:3210:FEDC:BA98:118.84.50.16 • Domain Names – Resolved by DNS Servers – FQDN: Fully Qualified Domain Name • www.csie.nuk.edu.tw. – One name can map to multiple IP addresses – One IP addresses can also have multiple names 3 Er.Sital Prasad Mandal bcanepaltu.com3
4.1 The InetAddress Class http://docs.oracle.com/javase/8/docs/api/java/net/InetAddress.html • Creating new InetAddress objects – N o public constructors; use static factory methods directly • Automatically connect to a DNS server to resolve a hostname • Throws a n UnknownHostException, a subclass of IOException, if not found • getByName(): lookup the name and the numeric address • getAllByName(): lookup all the addresses o f a host 4 Example 4-1. A program that prints the address of www.oreilly.com www.google.com/173.194.72.147 www.google.com/173.194.72.105 www.google.com/173.194.72.104 www.google.com/173.194.72.99 www.google.com/173.194.72.103 www.google.com/173.194.72.106 Er.Sital Prasad Mandal bcanepaltu.com4