关于网友提出的“ 我用以下代码内网IP可以取到网卡的IP,但在外网就取不到网卡的IP了,请给点提示”问题疑问,本网通过在网上对“ 我用以下代码内网IP可以取到网卡的IP,但在外网就取不到网卡的IP了,请给点提示”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: 我用以下代码内网IP可以取到网卡的IP,但在外网就取不到网卡的IP了,请给点提示
描述: 代码是:
public String getMacAddressIP(String remotePcIP){
String str="";
String macAddress="";
try {
Process pp= Runtime.getRuntime().exec ("nbtstat -A " + remotePcIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
for (int i = 1; i <100; i++)
{
str=input.readLine();
if (str!=null)
{
if(str.indexOf("MAC Address")>1)
{ macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
break;
}
}
}
}
catch (IOException ex) {}
return macAddress;
}
//通过机器名获取网卡地址
public String getMacAddressName(String remotePcIP){
String str="";
String macAddress="";
try {
Process pp= Runtime.getRuntime().exec ("nbtstat -a " + remotePcIP);
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader (ir);
for (int i = 1; i <100; i++)
{
str=input.readLine();
if (str!=null)
{
if(str.indexOf("MAC Address")>1)
{ macAddress=str.substring(str.indexOf("MAC Address")+14,str.length());
break;
}
}
}
}
catch (IOException ex) {}
return macAddress;
}
以上介绍了“ 我用以下代码内网IP可以取到网卡的IP,但在外网就取不到网卡的IP了,请给点提示”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3456805.html