package mynet;
import java.net.*;
public class MyIP
{
public static void main(String[] args) throws Exception
{
InetAddress address = InetAddress.getByName("www.csdn.net");
byte ip[] = address.getAddress();
for (byte ipSegment : ip)
System.out.print(ipSegment + " ");
System.out.println("");
for (byte ipSegment : ip)
{
int newIPSegment = (ipSegment < 0) ? 256 + ipSegment : ipSegment;
System.out.print(newIPSegment + " ");
}
}
}
运行结果:
-45 100 26 122
211 100 26 122