Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

36
LINES

< > BotCompany Repo | #1004196 // Detect Gateway On Android [Spike]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (128L/2K/4K).

1  
!752
2  
3  
import android.net.*;
4  
import android.net.wifi.WifiManager;
5  
6  
p {
7  
  String   s_dns1 ;
8  
  String   s_dns2;     
9  
  String   s_gateway;  
10  
  String   s_ipAddress;    
11  
  String   s_leaseDuration;    
12  
  String   s_netmask;  
13  
  String   s_serverAddress;
14  
  DhcpInfo d;
15  
  WifiManager wifii;
16  
17  
  wifii = (WifiManager) androidContext().getSystemService(Context.WIFI_SERVICE);
18  
  d=wifii.getDhcpInfo();
19  
20  
  s_dns1="DNS 1: "+intToIp(d.dns1);
21  
  s_dns2="DNS 2: "+intToIp(d.dns2);    
22  
  s_gateway="Default Gateway: "+intToIp(d.gateway);    
23  
  s_ipAddress="IP Address: "+intToIp(d.ipAddress); 
24  
  s_leaseDuration="Lease Time: "+intToIp(d.leaseDuration);       s_netmask="Subnet Mask: "+intToIp(d.netmask);    
25  
  s_serverAddress="Server IP: "+intToIp(d.serverAddress);
26  
27  
  S text = "Network Info\n"+s_dns1+"\n"+s_dns2+"\n"+s_gateway+"\n"+s_ipAddress+"\n"+s_leaseDuration+"\n"+s_netmask+"\n"+s_serverAddress;
28  
  print(text);
29  
}
30  
31  
static S intToIp(int addr) {
32  
  return  ((addr & 0xFF) + "." + 
33  
          ((addr >>>= 8) & 0xFF) + "." + 
34  
          ((addr >>>= 8) & 0xFF) + "." + 
35  
          ((addr >>>= 8) & 0xFF));
36  
}

Author comment

See http://stackoverflow.com/questions/5387036/programmatically-getting-the-gateway-and-subnet-mask-details

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, crvwmplrxojx, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, ybmhnqzijvxm

Comments [hide]

ID Author/Program Comment Date
1286 stefan On the tablet, anyway. Phone gives all 0 2016-08-09 22:48:55
1285 stefan Works! 2016-08-09 22:47:51

add comment

Snippet ID: #1004196
Snippet name: Detect Gateway On Android [Spike]
Eternal ID of this version: #1004196/1
Text MD5: 21e68e7dda12c14ef987345cecad7a5e
Transpilation MD5: 401cf46753c52c60daefefd9a6cacfd2
Author: stefan
Category: javax / android
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-09 22:45:11
Source code size: 1124 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 777 / 857
Referenced in: [show references]