android乙太網獲取ip
1. 如何獲取一台android手機的ip地址
果斷是坑你的錢啊。
下面是解決辦法
1.進入手機系統設置----無線和網路----wifi設置---菜單鍵----高級-----在下方ip設置里勾選「使用靜態ip」
2.在「使用靜態ip地址」下方,對應填寫:
ip地址:192.168.1.21(這個最後一位數可以隨意改,范圍0~255,如192.168.1.74)
網關:192.168.1.1(注意了,這里是你路由器的網關,這里是默認的地址)
網路掩碼:255.255.255.0(分為三種,詳細看電腦里的)
域名1:192.168.1.1(一般和上面的網關地址保持一致,直接上網的得修改為網路網關地址)
域名2:不填寫(特殊情況填寫)
3.保存!
之後你會發現你的wifi掉線後自動重新連接上了,之後不必再重啟路由,不會一直出現「正在獲取ip地址」的提示了
2. Android設置乙太網靜態IP
ifconfig eth0 [IP] netmask [NETMASK]
route add default gw [GATEWAY] dev eth0
setprop net.eth0.dns1 8.8.8.8
setprop net.eth0.dns2 4.4.4.4
----------------------------
getprop查看信息
激活(如果已經up可不用輸此命令): eth0 UP [IP ADDR] [NETMASK] 0x(該值從getprop中來)
你可以在adb下先測試一下 netcfg 可查看網卡信息
以上中括弧均去掉
3. 如何獲取Android IP地址
本文講述無線網和乙太網mac地址獲取的方法: 1.乙太網獲取mac地址 因為機頂盒系統是linux內核的,假設ethernet是eth0,那麼可以從以下文件中讀取相關信息:/sys/class/net/eth0/address方法1: public static String loadFileAsString(String filePath) throws java.io.IOException{ StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filePath)); char[] buf = new char[1024]; int numRead=0; while((numRead=reader.read(buf)) != -1){ String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); } reader.close(); return fileData.toString();}/** Get the STB MacAddress*/public String getMacAddress(){ try { return loadFileAsString("/sys/class/net/eth0/address") .toUpperCase().substring(0, 17); } catch (IOException e) { e.printStackTrace(); return null; }}方法2:NetworkInterface NIC = NetworkInterface.getByName("eth0"); byte[] buf = NIC.getHardwareAddress(); for (int i = 0; i < buf.length; i++) { mac = mac + byteHEX(buf);}if (mac != null && !"".equals(mac)) {
}2.wifi獲取mac和ip首先要在manifest.xml文件中添加許可權: <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>獲取mac的代碼如下WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = wifi.getConnectionInfo(); return info.getMacAddress();獲取Ip的代碼public String getLocalIpAddress() { try { for (Enumeration<NetworkInterface> en = NetworkInterface .getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); if (intf.getName().toLowerCase().equals("eth0")) { for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { String ipaddress = inetAddress.getHostAddress().toString(); if(!ipaddress.contains("::")){//ipV6的地址 return ipaddress; } } } } else { continue; } } } catch (Exception ex) { Log.e("WifiPreference IpAddress", ex.toString()); } return null; }
4. 求助 如何在程序中設置Android的乙太網IP地址
ifconfig eth0 [IP] netmask [NETMASK]
route add default gw [GATEWAY] dev eth0
setprop net.eth0.dns1 8.8.8.8
setprop net.eth0.dns2 4.4.4.4
----------------------------
getprop查看信息
激活(如果已經up可不用輸此命令): eth0 UP [IP ADDR] [NETMASK] 0x00001043(該值從getprop中來)
你可以在adb下先測試一下 netcfg 可查看網卡信息
以上中括弧均去掉
5. android 如何獲取本機ip地址最佳方法
/**
* 獲取ip地址
* @return
*/
public static String getHostIP() {
String hostIp = null;
try {
Enumeration nis = NetworkInterface.getNetworkInterfaces();
InetAddress ia = null;
while (nis.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) nis.nextElement();
Enumeration<InetAddress> ias = ni.getInetAddresses();
while (ias.hasMoreElements()) {
ia = ias.nextElement();
if (ia instanceof Inet6Address) {
continue;// skip ipv6
}
String ip = ia.getHostAddress();
if (!"127.0.0.1".equals(ip)) {
hostIp = ia.getHostAddress();
break;
}
}
}
} catch (SocketException e) {
Log.i("yao", "SocketException");
e.printStackTrace();
}
return hostIp;
}
6. android 中怎麼獲取電腦ip地址
1、 選擇: 設置 - 無線和網路 -WLAN設置 2、 按菜單鍵,然後選 高級 3、 IP地址設置選項,選擇「 使用靜態IP」 4、手動設置IP 地址, 大部分路由器的地址都是 192.168.1.** (XX 可以是 2-254 之間的任何數字,為了不和其他設備沖突,可以將數字設置大一些,例如 192.168.1.210等), 網關都是192.168.1.1,子網掩碼都是 255.255.255.0 ,實際情況根據路由器設置。 5、設置DNS伺服器地址,大部分路由器可以設置第一個DNS為路由器地(192.168.1.1),第二個DNS地址請查看路由器撥號狀態下的DNS地址,也可以直接打電話問網路服務提供商。 6、 然後 保存退出 就可以了。
7. Android獲取IP時的NetworkInterface對象的name屬性代表什麼意思
本文講述無線網和乙太網mac地址獲取的方法:1.乙太網獲取mac地址因為機頂盒系統是linux內核的,假設ethernet是eth0,那麼可以從以下文件中讀取相關信息:/sys/class/net/eth0/address方法1:(StringfilePath)throwsjava.io.IOException{StringBufferfileData=newStringBuffer(1000);BufferedReaderreader=newBufferedReader(newFileReader(filePath));char[]buf=newchar[1024];intnumRead=0;while((numRead=reader.read(buf))!=-1){StringreadData=String.valueOf(buf,0,numRead);fileData.append(readData);}reader.close();returnfileData.toString();}/**GettheSTBMacAddress*/publicStringgetMacAddress(){try{returnloadFileAsString("/sys/class/net/eth0/address").toUpperCase().substring(0,17);}catch(IOExceptione){e.printStackTrace();returnnull;}}方法2:NetworkInterfaceNIC=NetworkInterface.getByName("eth0");byte[]buf=NIC.getHardwareAddress();for(inti=0;i獲取mac的代碼如下WifiManagerwifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);WifiInfoinfo=wifi.getConnectionInfo();returninfo.getMacAddress();獲取Ip的代碼publicStringgetLocalIpAddress(){try{for(Enumerationen=NetworkInterface.getNetworkInterfaces();en.hasMoreElements();){NetworkInterfaceintf=en.nextElement();if(intf.getName().toLowerCase().equals("eth0")){for(EnumerationenumIpAddr=intf.getInetAddresses();enumIpAddr.hasMoreElements();){InetAddressinetAddress=enumIpAddr.nextElement();if(!inetAddress.isLoopbackAddress()){Stringipaddress=inetAddress.getHostAddress().toString();if(!ipaddress.contains("::")){//ipV6的地址returnipaddress;}}}}else{continue;}}}catch(Exceptionex){Log.e("WifiPreferenceIpAddress",ex.toString());}returnnull;}
8. android 手機客戶端的ip地址是靜態的,怎麼獲取ip
1、點擊手機下面的系統工具按鈕;
2、在彈出的菜單中選擇設置;
3、在彈出的菜單項中選擇無線和網路;
4、在無線網路設置中選擇wi_fi設置;
5、在wi_fi設置下點擊手機下面的系統工具按鈕 ,在彈出的菜單中選擇高級;
6、勾選使用靜態IP復選框.
7、點擊IP地址,設置IP,可根據wifi網所在網段來設置,這里設置為192.168.0.2 ,這里經需要說明的是IP地址設置范圍是192.168.0.2-192.168.0.254,在這個范圍內可以任意設置,不要使用192.168.0.1.因為這個會分配給路由.
9. Android 4.4 如何設置乙太網的IP地址,默認網關,子網掩碼以及DNS地址
最強的解決方法,打開WIFI,長按然後進入修改網路,點擊顯示高級選項,然後把IP設置為靜態,然後就能設置IP地址、網關、網路掩碼、以及dns地址
10. android怎麼獲取ip地址
一、首先介紹蘋果系統下查詢手機ip:
1、首先點擊【設置】按鈕
2、開啟無線區域網
3、然後選擇無線網路並連接,連接成功後,點擊所連接網路後面的驚嘆號圖標
4、然後就能看到該無線網路的詳細信息了,其中就包含了ip地址
二、介紹安卓系統下查詢手機ip地址,其方法和蘋果系統差不多:
打開系統設置,點擊進入
點擊wlan
然後進入高級設置
最後就能查看手機的mac地址和ip地址了