惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
U
Unit 42
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
S
SegmentFault 最新的问题
阮一峰的网络日志
阮一峰的网络日志
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
罗磊的独立博客
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
L
LangChain Blog
Engineering at Meta
Engineering at Meta
量子位
有赞技术团队
有赞技术团队
博客园 - 【当耐特】
A
About on SuperTechFans
Y
Y Combinator Blog

博客园 - 哑吧湖大水怪

MAF框架架构设计概览 rabbitmq 相关概念 使用AutoMapper时Expression的转换 unity 三种注入示例 DNS解析过程详解 手工设置Windows服务依赖关系 .NET Micro Framework简介 .net MF 学习 数码管显示 .NET MF固件部署 LED灯控制 Hello World 你懂的 .NET MF环境的安装 str to date C#实现在WinForm窗口标题栏上添加按钮 摄像头操作(转) 线程间操作控件 任务栏的显示与隐藏 winfrom 特效 [转载]
获取客户端相关信息
哑吧湖大水怪 · 2011-03-10 · via 博客园 - 哑吧湖大水怪

//添加组件System.Management
using System.Management;
using System.Runtime.InteropServices;

[DllImport(

"Iphlpapi.dll ")]
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport(
"Ws2_32.dll ")]
private static extern Int32 inet_addr(string ip); protected void Page_Load(object sender, EventArgs e)
{
try
{
string userip = Request.UserHostAddress;
Int32 ldest
= inet_addr(userip); //目的地的ip
Int32 lhost = inet_addr( " "); //本地服务器的ip
Int64 macinfo = new Int64();
Int32 len
= 6;
int res = SendARP(ldest, 0, ref macinfo, ref len);
string mac_src = macinfo.ToString( "X ");
if (mac_src == "0 ")
{
if (userip == "127.0.0.1 ")
userinfo.Text
= "正在访问Localhost! ";
else
userinfo.Text
= "欢迎来自IP为 " + userip + "的朋友! ";
return;
}
while (mac_src.Length < 12)
{
mac_src
= mac_src.Insert(0, "0 ");
}
string mac_dest = " ";
for (int i = 0; i < 11; i++)
{
if (0 == (i % 2))
mac_dest
= mac_dest.Insert(0, mac_src.Substring(i, 2));
}
userinfo.Text
= "欢迎来自IP为 " + userip + ",MAC地址为 " + mac_dest + "的朋友! ";
}
catch (Exception err)
{
Response.Write(err.Message);
}
}