mirror of
http://galexander.org/git/simplesshd.git
synced 2025-01-27 23:40:55 +00:00
this approach using java.net.NetworkInterface doesn't seem to work either
- it gives a random ipv6 address of no relation to any reality I'm interested in, I think
This commit is contained in:
parent
615e835880
commit
63d63e4f84
@ -7,7 +7,6 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<application android:label="SimpleSSHD" android:icon="@drawable/icon">
|
||||
<activity android:name="SimpleSSHD" android:label="SimpleSSHD">
|
||||
<intent-filter>
|
||||
|
@ -16,8 +16,10 @@ import android.net.Uri;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.BufferedReader;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleSSHD extends Activity
|
||||
{
|
||||
@ -163,14 +165,18 @@ public class SimpleSSHD extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
public String get_ip() {
|
||||
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wi = wm.getConnectionInfo();
|
||||
int ip = wi.getIpAddress();
|
||||
return
|
||||
String.valueOf((ip>>0)&0xff) + "." +
|
||||
String.valueOf((ip>>8)&0xff) + "." +
|
||||
String.valueOf((ip>>16)&0xff) + "." +
|
||||
String.valueOf((ip>>24)&0xff);
|
||||
public static String get_ip() {
|
||||
try {
|
||||
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface intf : interfaces) {
|
||||
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
|
||||
for (InetAddress addr : addrs) {
|
||||
if (!addr.isLoopbackAddress()) {
|
||||
return addr.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) { } // for now eat exceptions
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user