C#中通过SendARP读取MAC地址:

using System.Runtime.InteropServices;

publicstaticstring GetMacBySendARP(string remoteIP)
{
StringBuilder macAddress =new StringBuilder(); try
{
Int32 remote = inet_addr(remoteIP); Int64 macInfo =new Int64();
Int32 length =;
SendARP(remote, , ref macInfo, ref length); string temp = Convert.ToString(macInfo, ).PadLeft(, '').ToUpper(); int x =;
for (int i =; i <; i++)
{
if (i ==)
{
macAddress.Append(temp.Substring(x -, ));
}
else
{
macAddress.Append(temp.Substring(x -, ) +"-");
}
x -=;
} return macAddress.ToString();
}
catch
{
return macAddress.ToString();
}
} [DllImport("Iphlpapi.dll")]
privatestaticexternint SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport("Ws2_32.dll")]
privatestaticextern Int32 inet_addr(string ip);

C#中通过SendARP读取MAC地址的更多相关文章

  1. 几种C#程序读取MAC地址的方法

    原文:几种C#程序读取MAC地址的方法 以下是收集的几种C#程序读取MAC地址的方法,示例中是读取所有网卡的MAC地址,如果仅需要读取其中一个,稍作修改即可. 1 通过IPConfig命令读取MAC地 ...

  2. C# 几种读取MAC地址的方法

    以下是收集的几种C#程序读取MAC地址的方法,示例中是读取所有网卡的MAC地址,如果仅需要读取其中一个,稍作修改即可. 1 通过IPConfig命令读取MAC地址 ///<summary> ...

  3. 获得Unix/Linux系统中的IP、MAC地址等信息

    获得Unix/Linux系统中的IP.MAC地址等信息 中高级  |  2010-07-13 16:03  |  分类:①C语言. Unix/Linux. 网络编程 ②手册  |  4,471 次阅读 ...

  4. 使用 SendARP 获取 MAC 地址(使用SendARP API函数,很多相关文章)

    ARP 协议地址解析协议(ARP)是通过解析网路层地址来找寻数据链路层地址的一个在网络协议包中极其重要的网络传输协议.ARP 最初在 1982 年的 RFC 826 中提出并纳入互联网标准 STD 3 ...

  5. C#通过WMI读取MAC地址

    该方法依赖WMI的系统服务,该服务一般不会被关闭;但如果系统服务缺失或者出现问题,该方法无法取得MAC地址,需要重启Windows Management Instrumentation服务. publ ...

  6. c语言getipaddrtable获得ip地址与sendArp获得mac地址以及一些字节序问题记录

    https://docs.microsoft.com/zh-cn/windows/win32/api/iphlpapi/nf-iphlpapi-getipaddrtable msdn,有很多c的源码还 ...

  7. C#程序读取MAC地址的五种方法(转)

    public class GetMac { ///<summary> /// 根据截取ipconfig /all命令的输出流获取网卡Mac ///</summary> ///& ...

  8. 获取客户端Mac地址

    近期有个需求,需要获取客户端Mac地址作为白名单验证的依据.使用.net,B/S架构.先百度找了一些获取mac地址的方法, using System; using System.Collections ...

  9. (转)C#读取MAC的几种方法

    原文地址:http://www.cnblogs.com/diulela/archive/2012/04/07/2436111.html 1 通过IPConfig命令读取MAC地址 ///<sum ...

随机推荐

  1. VS中关于数据库的操作

    1.数据库迁移 第一步: 第二步: 在窗口中选择项目中的EntitiyFramwork项目(与数据库连接的文件集) 第三步: 输入update-database 二:数据对比 第一步: 第二步:选择需 ...

  2. Spring Cloud 5大组件

    服务发现——Netflix Eureka 客服端负载均衡——Netflix Ribbon 断路器——Netflix Hystrix 服务网关——Netflix Zuul 分布式配置——Spring C ...

  3. idea基于spring boot的依赖分开打包

    idea版本为2018.3.3 1.在菜单栏点击如图所示图标 Project Structure: 2.选择左侧菜单Artificial,然后在右侧点击 + 号按钮,在弹出的菜单中选择JAR -> ...

  4. 洛谷P1551 亲戚 (并查集模板题)

    链接 https://www.luogu.org/problemnew/show/P1551 代码 #include<bits/stdc++.h> using namespace std; ...

  5. The file is absent or does not have execute permission This file is needed to run this program

    tomcat下载后发现startup.sh文件启动不了 原因: 没有权限 解决方案:chmod 777 *.sh

  6. [HAOI2011] Problem b - 莫比乌斯反演

    复习一下莫比乌斯反演 首先很显然用一下容斥把它转化成求 \(ans=\sum_{i=1}^a \sum_{j=1}^b [{gcd(i,j)=d}]\) 我们可以定义 f(d) 和 F(d) 如下: ...

  7. linux - python:卸载

    [root@test ~]# rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除已安装程序及其关联[root@test ~]# ...

  8. liunx下安装Docker

    1.安装并启动docker 1.检查内核版本,必须是3.10及以上uname -r2.安装docker yum install docker命令安装(需要联网) [root@localhost ~]# ...

  9. MAC MAMP集成环境安装 PHP 扩展

    MAC MAMP集成环境安装 PHP扩展 开发环境中,对于需要维护很多 WEB 站点,以及可能会使用到很多不同的 PHP 版本,集成环境比较好用,在MAC 上 MAMP 集成环境是比较好用的,但是在安 ...

  10. CI系列之配置sonar

    基于GO项目 1.在jenkins新建sonar任务,设置2个变量用于接收代码分支和pipline的workspace[两个变量的作用在CI之Jenkinsfile中会讲到] A.添加构建参数 B.选 ...