Skip to content

Commit

Permalink
获取wifi或热点ip
Browse files Browse the repository at this point in the history
  • Loading branch information
wandersnail committed Jun 11, 2022
1 parent 3b6af4c commit 68b40fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'signing'

def lib_version = '1.3.4'
def lib_version = '1.3.5'
def user_name = 'wandersnail'
def lib_group = 'cn.wandersnail'
def lib_artifact = 'commons-android'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static List<NetInfo> getLocalNetInfos(@NonNull Context context) {
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
while (en.hasMoreElements()) {
NetworkInterface intf = en.nextElement();
if ("eth0".equals(intf.getName().toLowerCase(Locale.ENGLISH)) || "wlan0".equals(intf.getName().toLowerCase(Locale.ENGLISH))) {
if ("eth0".equals(intf.getName().toLowerCase(Locale.ENGLISH)) ||
"wlan1".equals(intf.getName().toLowerCase(Locale.ENGLISH)) ||
"wlan0".equals(intf.getName().toLowerCase(Locale.ENGLISH))) {
Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
while (enumIpAddr.hasMoreElements()) {
InetAddress inetAddress = enumIpAddr.nextElement();
Expand All @@ -63,7 +65,7 @@ public static List<NetInfo> getLocalNetInfos(@NonNull Context context) {
info.ip = ipaddress;
info.type = intf.getName().toLowerCase(Locale.ENGLISH);
info.mac = StringUtils.toHex(intf.getHardwareAddress(), ":");
if ("wlan0".equals(info.type)) {
if ("wlan0".equals(info.type) || "wlan1".equals(info.type)) {
if (isCurrentNetworkWifi(context)) {
int ipAddress = Objects.requireNonNull(wifiManager).getDhcpInfo().ipAddress;
info.isWifi = info.ip.equals(toAddressString(ipAddress));
Expand Down

0 comments on commit 68b40fc

Please sign in to comment.