티스토리 뷰
구글에서 검색해보니
Inet Address inetaddr = InetAddress.getLocalHost();
inetaddr.getHostAddress();
를 리눅스에서 사용하면, 127.0.0.1을 반환해 주는데, 이 주소는 LoopBack 주소를 말합니다.
윈도우에서는 실제 설정해놓은 ip를 반환한다고 합니다.
LoopBack 주소를 반환하는 것은 합당하다는 글이 좀 있었는데.
어쨌거나 제가 하고 싶은 것은 메시지 기반 통신에서 필요할 때마다 ServerSocket을 띄우고 메시지를 받을 Agent에게 접속할 ip와 port를 알려주어서 Binary File을 받아가게 하고 싶은 것입니다.
이를 위해서 NetworkInterface.getNetworkInterfaces()를 사용했습니다.
이 정적 메쏘드를 사용하면 시스템이 갖고 있는 NetworkInterface들을 Enumeration<NetworkInterface>로 반환해주는데, 이를 확인해보면 ip를 확인할 수 있습니다.
Enumeration<NetworkInterface> ne = NetworkInterface.getNatworkInterfaces();
while ( ne.hasMoreElements()) {
NetworkInterface ni = ne.nextElement();
System.out.println("Name : " + ni.getName());
Enumeration<InetAddress> inets = ni.getInetAddresses()/;
while(inets.hasMoreElements();
InetAddress iaddr = inets.nextElement();
System.out.println("INet --> isSiteLocalAddress() -->" + iaddr.isSiteLocalAddress());
}
}
간략히 위와 같은 식으로 해서 NetworkInterface의 이름이 regular expression "eth[0-9]'인 것을 찾은 다음, isSiteLocalAdresss()를 통해 true인 것을 확인하면, local ip를 확인할 수 있습니다.
검색한 글에서 추천하는 방법은 외부와의 socket연결이 되어 있다면 그 socket연결을 통해서 ip를 확인하는 방법이 좋다고 합니다.
꼼수꼼수...
Inet Address inetaddr = InetAddress.getLocalHost();
inetaddr.getHostAddress();
를 리눅스에서 사용하면, 127.0.0.1을 반환해 주는데, 이 주소는 LoopBack 주소를 말합니다.
윈도우에서는 실제 설정해놓은 ip를 반환한다고 합니다.
LoopBack 주소를 반환하는 것은 합당하다는 글이 좀 있었는데.
어쨌거나 제가 하고 싶은 것은 메시지 기반 통신에서 필요할 때마다 ServerSocket을 띄우고 메시지를 받을 Agent에게 접속할 ip와 port를 알려주어서 Binary File을 받아가게 하고 싶은 것입니다.
이를 위해서 NetworkInterface.getNetworkInterfaces()를 사용했습니다.
이 정적 메쏘드를 사용하면 시스템이 갖고 있는 NetworkInterface들을 Enumeration<NetworkInterface>로 반환해주는데, 이를 확인해보면 ip를 확인할 수 있습니다.
Enumeration<NetworkInterface> ne = NetworkInterface.getNatworkInterfaces();
while ( ne.hasMoreElements()) {
NetworkInterface ni = ne.nextElement();
System.out.println("Name : " + ni.getName());
Enumeration<InetAddress> inets = ni.getInetAddresses()/;
while(inets.hasMoreElements();
InetAddress iaddr = inets.nextElement();
System.out.println("INet --> isSiteLocalAddress() -->" + iaddr.isSiteLocalAddress());
}
}
간략히 위와 같은 식으로 해서 NetworkInterface의 이름이 regular expression "eth[0-9]'인 것을 찾은 다음, isSiteLocalAdresss()를 통해 true인 것을 확인하면, local ip를 확인할 수 있습니다.
검색한 글에서 추천하는 방법은 외부와의 socket연결이 되어 있다면 그 socket연결을 통해서 ip를 확인하는 방법이 좋다고 합니다.
꼼수꼼수...
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- smplayer
- subervsion
- pl/java
- 리눅스
- Fedora 9
- Eclipse
- gl2
- SimpleDateFormat
- 출력드라이버
- Java
- Linux
- Arrays
- 파란 화면을 보았니
- JavaMail
- yum update
- OO3
- 병합정렬
- Fedora 8
- 모토로이
- 다음팟인코더
- PostgreSQL
- OpenJDK6
- GMT
- output driver
- userguide
- IcedTea6
- Numbering
- tsclient
- openoffice
- xml2
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
글 보관함