机器标识
例:
import java.net.InetAddress;
import java.net.UnknownHostException;
public class WhoAmI {
public static void main(String[] args) throws UnknownHostException {
// TODO Auto-generated method stub
if(args.length!=1){
System.err.println("111");
System.exit(1);
}
InetAddress address= InetAddress.getByName(args[0]);
System.out.println(address);
}
}
命令行运行 java WhoAmI B6ELLFJRDT5EEEV结果:
(B6ELLFJRDT5EEEV是本地自己的计算机名)
B6ELLFJRDT5EEEV/192.168.238.1
本地主机地址:
InetAddress address= InetAddress.getByName("localhost");
InetAddress address= InetAddress.getByName(null);
InetAddress address= InetAddress.getByName("127.0.0.1");
System.out.println(address);
注:上面三种写法都一样,最终结果都是输出:
localhost/127.0.0.1
端口号:
一个端口号对应一种服务。