1.时间戳是System.currentTimeMillis(),需要精确到秒就用System.currentTimeMillis() / 1000
2.获取本机IP的方法
String addr = InetAddress.getLocalHost().getHostAddress();
这个只能在windows上获取,在linux系统下只会得到广播地址
所以要windows和linux兼容的情况:
private static String getHostIp(){
try{
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()){
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()){
InetAddress ip = (InetAddress) addresses.nextElement();
if (ip != null
&& ip instanceof Inet4Address
&& !ip.isLoopbackAddress() //loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255