Commit 4aeb8643 authored by 郝彦辉's avatar 郝彦辉

百行每天的重新报送优化成定时任务

parent 29d0decb
......@@ -11,6 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Map;
@Slf4j
......@@ -214,4 +218,36 @@ public class ManualToolController {
}
@RequestMapping("/getIp")
public String getIp(){
try{
return getServerIp();
}catch(Exception e){
return "获取本地ip异常";
}
}
private String getServerIp() {
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 */
&& ip.getHostAddress().indexOf(":") == -1) {
System.out.println("本机的IP = " + ip.getHostAddress());
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
log.error("获取本地ip异常", e);
}
return null;
}
}
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