{ "question_id": 159444, "question_title": "自动获取计算机的ip地址和mac地址", "question_content": "自动获取计算机的ip地址和mac地址", "difficulty": "简单", "answer_id": 24936, "answer_content": "\n\n```\n public static String getMacAddressIP(String remotePcIP) {\n String str = \"\";\n String macAddress = \"\";\n try {\n Process pp = Runtime.getRuntime().exec(\"nbtstat -A \" + remotePcIP);\n InputStreamReader ir = new InputStreamReader(pp.getInputStream());\n LineNumberReader input = new LineNumberReader(ir);\n for (int i = 1; i < 100; i++) {\n str = input.readLine();\n if (str != null) {\n if (str.indexOf(\"MAC Address\") > 1) {\n macAddress = str.substring(\n str.indexOf(\"MAC Address\") + 14, str.length());\n break;\n }\n }\n }\n } catch (IOException ex) {\n }\n return macAddress;\n }\n```\n\n", "tag_name": "java", "java": "import java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.LineNumberReader;\nclass java_15944{\n public static String getMacAddressIP(String remotePcIP) {\n String str = \"\";\n String macAddress = \"\";\n try {\n Process pp = Runtime.getRuntime().exec(\"nbtstat -A \" + remotePcIP);\n InputStreamReader ir = new InputStreamReader(pp.getInputStream());\n LineNumberReader input = new LineNumberReader(ir);\n for (int i = 1; i < 100; i++) {\n\tstr = input.readLine();\n\tif (str != null) {\n\t if (str.indexOf(\"MAC Address\") > 1) {\n\t macAddress = str.substring(\n\t\tstr.indexOf(\"MAC Address\") + 14, str.length());\n\t break;\n\t }\n\t}\n }\n } catch (IOException ex) {\n }\n return macAddress;\n }\n}", "topic_link": "https://bbs.csdn.net/topics/600469874", "status": 0, "keywords": "ip地址,mac地址", "license": "csdn.net", "notebook": { "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/19.ipynb?type=file" } }