Commit 336c5057 authored by zhushanglei's avatar zhushanglei

init

parent 369e781f
......@@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
* @author yuli
......@@ -72,6 +73,18 @@ public class TcpServer {
InetAddress addr = InetAddress.getLocalHost();
logger.info("Local HostAddress:"+addr.getHostAddress());
String hostname = addr.getHostName();
byte[] mac = NetworkInterface.getByInetAddress(addr).getHardwareAddress();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mac.length; i++) {
if (i != 0) {
sb.append("-");
}
// mac[i] & 0xFF 是为了把byte转化为正整数
String s = Integer.toHexString(mac[i] & 0xFF);
sb.append(s.length() == 1 ? 0 + s : s);
}
logger.info("mac: "+sb.toString());
logger.info("Local host name: "+hostname);
b.bind(addr.getHostAddress(), PORT).sync();
logger.info("TCP Server Started");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment