我正在尝试从传入的请求对象中获取MAC地址。我的应用程序运行在nginx代理之后,所以为了获取IP地址,我使用了下面的语法,它工作得很好。
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
同样,还有一种方法可以获取已发出请求的MAC地址。我偶然发现了这个包,我不确定这是否会有帮助。基本上,我需要获取每个传入请求的MAC和IP地址。
public static void main(String[] args) {
try {
InetAddress address = InetAddress.getLocalHost();
// InetAddress address = InetAddress.getByName("192.168.46.53");
/*
* Get NetworkInterface for the current host and then read the
* hardware address
我试图在没有连接到互联网的情况下获取我的PC的MAC地址,我使用了以下代码
InetAddress ip;
try {
ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mac.length;
我是否可以获得连接到我的站点的MAC地址。
此代码获取mac地址host并返回错误权限。
String macadress = string.Empty;
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
OperationalStatus ot = nic.OperationalStatus;
if (nic.OperationalStatus == OperationalStatus.Up)
是否有类似于此代码的命令可打印出存储在此变量中的IP的MAC地址或“哈希码”?我做了一些研究,看起来这可能是一项非常复杂甚至不可能完成的任务。但我认为值得一问。(编辑:我搜索的任何IP都是我的网络的内部IP )。
IPAddress addr = IPAddress.Parse(inputIP); //uses the input IP data into the addr variable to get host
IPHostEntry entry = Dns.GetHostEntry(addr); //Get hostname