获取客户端的IP地址或获取连接到热点的Android客户端的信息(SSID)(圈养后) [英] Getting the IP address of client or getting the information(SSID) of Clients connected to Hotspot Android (after Tethering)
问题描述
我得到了,我得到了一个开放式(非加密)热点的Android程序的无线网络共享。我喜欢观看客户端(SSID和IP地址)的连接到我的热点的细节。 我用SocketAddress的socketid = socket.getLocalSocketAddress();同时还采用
公共无效getLocalIpAddressString(){
尝试 {
对于(枚举<的NetworkInterface> EN = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements()){
NetworkInterface的INTF = en.nextElement();
对于(枚举< InetAddress类> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements()){
InetAddress类InetAddress类= enumIpAddr.nextElement();
如果(!inetAddress.isLoopbackAddress()){
//返回inetAddress.getHostAddress()的toString()。
Toast.makeText(getApplicationContext(),inetAddress.getHostAddress()的toString()
Toast.LENGTH_SHORT).show();
}
}
}
}赶上(例外前){
Log.e(IPADDRESS,ex.toString());
}
//返回null;
}
这些只会返回本地IP,但你可以请帮我在得到客户端连接到我的WiFi热点的IP地址。谢谢你。
解决方案最后,我得到了获取客户端IP连接到我的热点响应
公共无效getClientList(){
INT macCount = 0;
的BufferedReader BR = NULL;
尝试 {
BR =新的BufferedReader(新的FileReader(的/ proc /净/ ARP));
串线;
而((行= br.readLine())!= NULL){
串[]分裂= line.split(+);
如果(分裂= NULL和放大器;!&安培; splitted.length> = 4){
//基本的完整性检查
串MAC =分裂[3];
如果(mac.matches(..:..:..:..:..:..)){
macCount ++;
ClientList.add(客户端(+ macCount +));
IpAddr.add(分裂[0]);
HWAddr.add(分裂[3]);
Device.add(分裂[5]);
Toast.makeText(
getApplicationContext(),
Mac_Count+ macCount +MAC_ADDRESS
+ MAC,Toast.LENGTH_SHORT).show();
的for(int i = 0; I< splitted.length;我++)
的System.out.println(Addressssssss
+分裂[I]);
}
}
}
I got the program for Wifi tethering which i got a open (non secured) hot spot in Android. I like to view the details of client (SSID and IP address) connected to my hotspot. I used SocketAddress socketid=socket.getLocalSocketAddress(); and also used
public void getLocalIpAddressString() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
// return inetAddress.getHostAddress().toString();
Toast.makeText(getApplicationContext(), inetAddress.getHostAddress().toString(),
Toast.LENGTH_SHORT).show();
}
}
}
} catch (Exception ex) {
Log.e("IPADDRESS", ex.toString());
}
// return null;
}
These will return only the local IP but can you please help me in getting the IP address of client connected to my Wifi Hotspot. Thank you.
Finally I got the response for getting the Client IP connected to my hotspot. The code below will track the Mac and IP changes each time a new client is added to my network
public void getClientList() {
int macCount = 0;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
if (splitted != null && splitted.length >= 4) {
// Basic sanity check
String mac = splitted[3];
if (mac.matches("..:..:..:..:..:..")) {
macCount++;
ClientList.add("Client(" + macCount + ")");
IpAddr.add(splitted[0]);
HWAddr.add(splitted[3]);
Device.add(splitted[5]);
Toast.makeText(
getApplicationContext(),
"Mac_Count " + macCount + " MAC_ADDRESS "
+ mac, Toast.LENGTH_SHORT).show();
for (int i = 0; i < splitted.length; i++)
System.out.println("Addressssssss "
+ splitted[i]);
}
}
}
这篇关于获取客户端的IP地址或获取连接到热点的Android客户端的信息(SSID)(圈养后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!