모든 OS에서 ip 가져오도록 수정 (기존 방식은 windows에서만 사용 가능)

This commit is contained in:
JooYoung 2022-12-08 15:17:45 +09:00
parent 90415468d0
commit 58174df6e5
2 changed files with 31 additions and 9 deletions

View File

@ -1,6 +1,9 @@
package kcc.kccadr.message;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.List;
import javax.annotation.Resource;
@ -52,15 +55,33 @@ public class SchedulerUtil {
@Scheduled(cron = "0 0/10 * * * *")
@SchedulerLock(name = "kakaoAtSendPrcs", lockAtMostForString = ONE_MIN, lockAtLeastForString = ONE_MIN)
public void kakaoAtSendPrcs() throws Exception {
String ip = null;
System.out.println("===========at scheduler run============");
String hostAddr = null;
//모든 OS에서 서버 고정 IP를 가져오기
try {
Enumeration<NetworkInterface> nienum = NetworkInterface.getNetworkInterfaces();
while (nienum.hasMoreElements()) {
NetworkInterface ni = nienum.nextElement();
Enumeration<InetAddress> kk= ni.getInetAddresses();
while (kk.hasMoreElements()) {
InetAddress inetAddress = kk.nextElement();
if (!inetAddress.isLoopbackAddress() &&
!inetAddress.isLinkLocalAddress() &&
inetAddress.isSiteLocalAddress()) {
hostAddr = inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
try {
ip = InetAddress.getLocalHost().getHostAddress();
hostAddr = InetAddress.getLocalHost().getHostAddress();
System.out.println("===========at scheduler run============");
System.out.println("server ip ============" + ip);
if(ip.equals(myLocalIp) || ip.equals(devIp) || ip.equals(dmzIp1) || ip.equals(dmzIp2) ) {
System.out.println("server ip ============" + hostAddr);
if(hostAddr.equals(myLocalIp) || hostAddr.equals(devIp) || hostAddr.equals(dmzIp1) || hostAddr.equals(dmzIp2) ) {
//접속 서버 분기처리 필요
List<KakaoAtSendVO> list = kakaoAtSendService.selectKakaoAtList();
@ -79,13 +100,14 @@ public class SchedulerUtil {
}
}
System.out.println("===========at scheduler finish============");
} catch (Exception e) {
System.out.println(e.getMessage());
}
System.out.println("===========at scheduler finish============");
}
@Bean

View File

@ -205,6 +205,6 @@ Globals.Kakao.Key=bf3de0d897afe0e4bef0775f7086f048
# \uce74\uce74\uc624\uc54c\ub9bc\ud1a1(\ube44\uc988\ubfcc\ub9ac\uc624) API URL
#\uac1c\ubc1c\uc11c\ubc84
#Globals.BizPpurio.siteUrl=https://dev-api.bizppurio.com
Globals.BizPpurio.siteUrl=https://dev-api.bizppurio.com
#\uc2e4\uc11c\ubc84
Globals.BizPpurio.siteUrl=https://api.bizppurio.com
#Globals.BizPpurio.siteUrl=https://api.bizppurio.com