Redian新闻
>
how can I test own local IP address
avatar
how can I test own local IP address# Java - 爪哇娇娃
p*p
1
I want to test if a giving IP address is my PC's IP address
address = "193.175.XXXXXX";
InetAddress ia = InetAddress.getByName(address);
if(ia.isSiteLocalAddress()) {
....
does not work.
avatar
m*t
2
Define "my PC's IP address". 8-)

【在 p***p 的大作中提到】
: I want to test if a giving IP address is my PC's IP address
: address = "193.175.XXXXXX";
: InetAddress ia = InetAddress.getByName(address);
: if(ia.isSiteLocalAddress()) {
: ....
: does not work.

avatar
m*t
3

Interesting idea. Does this work with a multi-network card config? Would be
very useful indeed if it does.
avatar
t*g
4
Java doesn't work well with multiple NIC cards, we have to specify which
card
to use during install, otherwise it could mess up.

be

【在 m******t 的大作中提到】
:
: Interesting idea. Does this work with a multi-network card config? Would be
: very useful indeed if it does.

avatar
p*p
5
可是我怎么能知道这个电脑的名字呢,因为
可能安装在任何机器上。
就是一个程序,(1)我希望能得到本机的IP地址,
(2)如果用户手动设置,我希望验证一下是不是本机的

【在 t*********g 的大作中提到】
: Java doesn't work well with multiple NIC cards, we have to specify which
: card
: to use during install, otherwise it could mess up.
:
: be

avatar
c*y
6
如果是在windows上,有个环境变量computername;其他OS应该有类似
机制

【在 p***p 的大作中提到】
: 可是我怎么能知道这个电脑的名字呢,因为
: 可能安装在任何机器上。
: 就是一个程序,(1)我希望能得到本机的IP地址,
: (2)如果用户手动设置,我希望验证一下是不是本机的

avatar
m*t
7

I can't think of any Java standard API that does this.

【在 p***p 的大作中提到】
: 可是我怎么能知道这个电脑的名字呢,因为
: 可能安装在任何机器上。
: 就是一个程序,(1)我希望能得到本机的IP地址,
: (2)如果用户手动设置,我希望验证一下是不是本机的

avatar
t*g
8
InetAddress address = InetAddress.getByName("your computer's
name");
String ip = address.getHostAddress();
boolean bool = address.isSiteLocalAddress();
//or compare the IP address

【在 m******t 的大作中提到】
:
: I can't think of any Java standard API that does this.

avatar
t*g
9
Java doesn't work well with multiple NIC cards, we have to specify which
card
to use during install, otherwise it could mess up.

be

【在 m******t 的大作中提到】
:
: I can't think of any Java standard API that does this.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。