// 获取mac地址
public static String getMacAddress() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
byte[] mac = null;
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
continue;
} else {
mac = netInterface.getHardwareAddress();
if (mac != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length; i++) {
sb.append(String.format("X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
if (sb.length() > 0) {
return sb.toString();
}
}
}
}
} catch (Exception e) {
_logger.error("MAC地址获取失败", e);
}
return "";
}
// 获取ip地址
public static String getIpAddress() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
continue;
} else {
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
ip = addresses.nextElement();
if (ip != null && ip instanceof Inet4Address) {
return ip.getHostAddress();
}
}
}
}
} catch (Exception e) {
_logger.error("IP地址获取失败", e);
}
return "";
}
public final static String WIN_OS = "WINDOWS";
public final static String MAC_OS = "MAC";
public final static String LINUX_OS = "LINUX";
public final static String OTHER_OS = "OTHER";
public static String getOS() {
if (SystemUtils.IS_OS_WINDOWS){
return WIN_OS;
}
if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX){
return MAC_OS;
}
if (SystemUtils.IS_OS_UNIX){
return LINUX_OS;
}
return OTHER_OS;
}
/**
* 设置http代理
*/
public static void setHttpProxy() {
Properties prop = System.getProperties();
// 设置http访问要使用的代理服务器的地址
prop.setProperty("http.proxyHost", HTTP_PROXY_HOST);
// 设置http访问要使用的代理服务器的端口
prop.setProperty("http.proxyPort", HTTP_PROXY_PORT);
// 设置不需要通过代理服务器访问的主机,可以使用*通配符,多个地址用|分隔
prop.setProperty("http.nonProxyHosts", RemoteConfig.PROXT_FILTER_DOMAIN);
}
/**
* 移除http代理
*/
public static void removeHttpProxy() {
Properties prop = System.getProperties();
prop.remove("http.proxyHost");
prop.remove("http.proxyPort");
prop.remove("http.nonProxyHosts");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有