package fengzhuang;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddr {
public String getId() throws IOException {
InetAddress inetAddress = InetAddress.getLocalHost();
return inetAddress.getHostAddress();
}
public String getId(String hostName) throws IOException {
InetAddress inetAddress = InetAddress.getByName(hostName);
return inetAddress.getHostAddress();
}
/*
* 根据主机名,原始Ip地址获得
*/
public String getId(String hostName, byte []beginIp) throws UnknownHostException {
InetAddress inetAddress = InetAddress.getByAddress(hostName, beginIp);
return inetAddress.getHostAddress();
}
public void print(String value) {
System.out.println(value);
}
public static void main(String [] args) throws IOException {
InetAddr id = new InetAddr();
System.out.println(id.getId("www.qq.com"));
}
}
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class InetAddr {
public String getId() throws IOException {
InetAddress inetAddress = InetAddress.getLocalHost();
return inetAddress.getHostAddress();
}
public String getId(String hostName) throws IOException {
InetAddress inetAddress = InetAddress.getByName(hostName);
return inetAddress.getHostAddress();
}
/*
* 根据主机名,原始Ip地址获得
*/
public String getId(String hostName, byte []beginIp) throws UnknownHostException {
InetAddress inetAddress = InetAddress.getByAddress(hostName, beginIp);
return inetAddress.getHostAddress();
}
public void print(String value) {
System.out.println(value);
}
public static void main(String [] args) throws IOException {
InetAddr id = new InetAddr();
System.out.println(id.getId("www.qq.com"));
}
}