package com.moon.server.entity.other;
|
|
import java.net.Inet4Address;
|
import java.net.InetAddress;
|
import java.net.NetworkInterface;
|
import java.net.SocketException;
|
import java.util.Enumeration;
|
|
@SuppressWarnings("ALL")
|
public class ReqParamFloatServer {
|
private String id;
|
|
private String port;
|
|
private String modules;
|
|
private int availableNum;
|
|
private long time;
|
|
private String localId;
|
|
private String cmdType;
|
|
public ReqParamFloatServer() {
|
this.localId = a();
|
}
|
|
public ReqParamFloatServer(String id, String port) {
|
this.id = id;
|
this.port = port;
|
this.localId = a();
|
}
|
|
public String getPort() {
|
return this.port;
|
}
|
|
public void setPort(final String port) {
|
this.port = port;
|
}
|
|
public String getId() {
|
return this.id;
|
}
|
|
public void setId(final String id) {
|
this.id = id;
|
}
|
|
public String getModules() {
|
return this.modules;
|
}
|
|
public void setModules(final String modules) {
|
this.modules = modules;
|
}
|
|
public int getAvailableNum() {
|
return this.availableNum;
|
}
|
|
public void setAvailableNum(final int availableNum) {
|
this.availableNum = availableNum;
|
}
|
|
public long getTime() {
|
return this.time;
|
}
|
|
public void setTime(final long time) {
|
this.time = time;
|
}
|
|
public String getLocalId() {
|
return this.localId;
|
}
|
|
public String getCmdType() {
|
return this.cmdType;
|
}
|
|
public void setCmdType(final String cmdType) {
|
this.cmdType = cmdType;
|
}
|
|
public static String a() {
|
String string = "";
|
try {
|
final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
while (networkInterfaces.hasMoreElements()) {
|
final NetworkInterface networkInterface;
|
if (!(networkInterface = networkInterfaces.nextElement()).isLoopback() && !networkInterface.isVirtual() && networkInterface.isUp()) {
|
final Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
final byte[] hardwareAddress;
|
if ((hardwareAddress = networkInterface.getHardwareAddress()) == null || networkInterface.getName().contains("docker")) {
|
continue;
|
}
|
while (inetAddresses.hasMoreElements()) {
|
final InetAddress inetAddress;
|
if ((inetAddress = inetAddresses.nextElement()) != null && inetAddress instanceof Inet4Address) {
|
final String a = a(inetAddress);
|
string = String.valueOf(inetAddress.getHostAddress()) + "|" + a;
|
if (!a.isEmpty()) {
|
return string;
|
}
|
continue;
|
}
|
}
|
}
|
}
|
} catch (SocketException ex) {
|
//
|
}
|
return string;
|
}
|
|
private static String a(final InetAddress addr) {
|
String upperCase = "";
|
try {
|
final byte[] hardwareAddress = NetworkInterface.getByInetAddress(addr).getHardwareAddress();
|
final StringBuffer sb = new StringBuffer("");
|
for (int i = 0; i < hardwareAddress.length; ++i) {
|
if (i != 0) {
|
sb.append("-");
|
}
|
final String hexString;
|
if ((hexString = Integer.toHexString(hardwareAddress[i] & 0xFF)).length() == 1) {
|
sb.append("0".concat(String.valueOf(hexString)));
|
} else {
|
sb.append(hexString);
|
}
|
}
|
upperCase = sb.toString().toUpperCase();
|
} catch (Exception ex) {
|
//
|
}
|
return upperCase;
|
}
|
}
|