Commit 4bf5d6ee by 焦荣

修改客户端采集功能

parent af523683
...@@ -117,44 +117,41 @@ public class SysUitl { ...@@ -117,44 +117,41 @@ public class SysUitl {
return mac; return mac;
} }
/*获取服务器端的MAC //根据 nbtstat -A 通过客户端IP获取MAC
public static String getMacAddress() public static String getkhdMac(String ip){
{
String mac = ""; String mac = "";
String line = ""; try {
String os = System.getProperty("os.name"); Process p = null;
if (os != null && os.startsWith("Windows")) try {
{ String comstr = "nbtstat -A " + ip ;
try p = Runtime.getRuntime().exec(comstr);
{ } catch (IOException e) {
String command = "cmd.exe /c ipconfig /all"; e.printStackTrace();
Process p = Runtime.getRuntime().exec(command); }
InputStreamReader ir = new InputStreamReader(p.getInputStream(), "GBK");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream(),"GBK")); LineNumberReader input = new LineNumberReader(ir);
p.waitFor();
while((line = br.readLine()) != null) boolean flag = true;
{ while(flag) {
System.out.println("==www=" + line); String str = input.readLine();
//if (line.indexOf("Physical Address" ) > 0) // MAC 地址 = 48-8A-D2-42-5C-D8
if (line.indexOf("物理地址" ) > 0 || line.indexOf("Physical Address" )>0) if (str!=null && str.indexOf("MAC") > 1) {
{ int start = str.indexOf("=");
int index = line.indexOf(":") + 2; if (start != -1) {
mac = str.substring(start + 1).trim();
mac = line.substring(index); }
break;
}else if(str==null){
break; break;
} }
} }
} catch (Exception e) {
br.close(); e.printStackTrace(System.out);
} catch (IOException e) {}
} }
return mac; return mac;
}*/ }
//获取MAC地址的方法 //获取服务端MAC地址的方法
public static String getMACAddress(){ public static String getMACAddress(){
//获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。 //获得网络接口对象(即网卡),并得到mac地址,mac地址存在于一个byte数组中。
byte[] mac = new byte[0]; byte[] mac = new byte[0];
...@@ -187,28 +184,8 @@ public class SysUitl { ...@@ -187,28 +184,8 @@ public class SysUitl {
public static void main(String[] args) throws UnknownHostException, SocketException { public static void main(String[] args) throws UnknownHostException, SocketException {
//String ip = "192.068.0.103"; String ip = "192.168.0.103";
//System.out.println("===" + getMac(ip)); System.out.println("===" + getkhdMac(ip));
// TODO Auto-generated method stub
/* InetAddress ia=null;
try {
ia=ia.getLocalHost();
String localname=ia.getHostName();
String localip=ia.getHostAddress();
System.out.println("本机名称是:"+ localname);
System.out.println("本机的ip是 :"+localip);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InetAddress ia1 = InetAddress.getLocalHost();//获取本地IP对象
try {
System.out.println("MAC ......... "+getMACAddress(ia1));
} catch (Exception e) {
e.printStackTrace();
}*/
System.out.println("MAC ......... "+getMACAddress());
} }
......
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