8

如何在Android扫描局域网内的设备mac地址

 2 years ago
source link: https://www.myfreax.com/how-to-scan-the-mac-address-of-the-device-in-the-local-area-network-on-android/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

在Linux中要找到局域网内所有设备的Mac地址会非常简单,有好多工具或者命令做到这一点。比如fing,arp,ip neigh 。但在Android中arp的缓存,从Android 10之后就不能读取,也就剩下ip neigh 这个命令可用。

ip neigh是iproute2的一部分。iproute2是一组用户空间程序,用于控制和监视 Linux内核中网络的各个方面,包括路由、网络接口、隧道、流量控制和与网络相关的设备驱动程序。

在本教程我们将说明如何在Android扫描局域网内的设备mac地址。

为此,我们编写了一个arp_scanner程序,它是一个Flutter插件,它将会返回局域网中同一网段的所有可用设备。返回的信息包括设备的IP地址,Mac地址,主机名,网卡的制造商。

arp_scanner插件限制

我们编写arp_scanner插件仅支持使用Android SDK 29的版本,它可以工作在2.4G的wifi和5G wifi。还有一个缺点就是在5G wifi网络的情况下,主机名将会解释不了。

将arp_scanner作为你项目的依赖添加到pubspec.yaml file。修改app项目的build.gradle的compileSdkVersion为29:

android {
....    
compileSdkVersion 29 
....
}

并将项目Kotlin版本改为1.5.30或者更新:

buildscript {
  ...
  ext.kotlin_version = '1.5.30'
  ...
}

你可以在flutter插件的官方站点找关于arp_scanner的示例。

更新Mac地址与厂商关系的数据库(可选)

首先克隆仓库到本地,然后配置golang的开发环境,并执行下面golang程序,它将从ieee.org电气工程协会下载Mac地址与厂商关系的数据库,并写入sqlite数据库中:

go mod tidy 
go run createMacVendorDB.go

更新完数据库后请直接使用本地仓库作为依赖添加你的项目中。

解决 Duplicate class com.google.gson的问题

android {
  configurations {
    all {
      exclude module:'gson'
    }
  }
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK