实验室里发现Wifi,代理又得经过认证MAC地址。通过查询Android的API文档,可以通过以下代码进行MAC地址等信息的查询。(Android 2.2)
main.xml
xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:id="@+id/info"/>
LinearLayout>
AndroidManifest.xml
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="proj.javaangle" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Mac" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
application>
manifest>
Mac.java
package proj.javaangle;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.TextView;
public class Mac extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView infoText = (TextView) this.findViewById(R.id.info);
infoText.setText(getInfo());
}
private String getInfo()
{
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String maxText = info.getMacAddress();
String ipText = intToIp(info.getIpAddress());
String status = "";
if (wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
{
status = "WIFI_STATE_ENABLED";
}
String ssid = info.getSSID();
int networkID = info.getNetworkId();
int speed = info.getLinkSpeed();
return "mac:" + maxText + "\n\r"
+ "ip:" + ipText + "\n\r"
+ "wifi status :" + status + "\n\r"
+ "ssid :" + ssid + "\n\r"
+ "net work id :" + networkID + "\n\r"
+ "connection speed:" + speed + "\n\r"
;
}
private String intToIp(int ip)
{
return (ip & 0xFF) + "." + ((ip >> 8) & 0xFF) + "." + ((ip >> 16) & 0xFF) + "."
+ ((ip >> 24) & 0xFF);
}
}
程序运行结果如下 :
总结:
1.通过Android SDK API查询,