在我的应用程序中,我有一个Mac地址列表,我想从中获取设备的详细信息(例如操作系统型号等)。我尝试了许多在线可用的解决方案,但似乎都无济于事,但是有一个Mac供应商我尝试实现的api,通过它我只能获取设备制造商的名称,但这不满足我的应用程序目标。 所以我的问题是如何从Mac地址或IP地址以编程方式获取设备详细信息? 这是我用来调用Mac供应商api的代码,但是我不想在我的应用程序中使用任何api:
String macAdress = "5caafd1b0019";
String dataUrl = "http://api.macvendors.com/" + macAdress;
HttpURLConnection connection = null;
try {
URL url = new URL(dataUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.flush();
wr.close();
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
StringBuffer response = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {response.append(line);response.append('\r');}
rd.close();
String responseStr = response.toString();
Log.d("Server response", responseStr);
} catch (Exception e) {e.printStackTrace();} finally {if (connection != null) {connection.disconnect();}}