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

推荐订阅源

人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
B
Blog
D
Docker
C
Check Point Blog
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
罗磊的独立博客
月光博客
月光博客
博客园 - Franky
L
LangChain Blog
H
Help Net Security
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
小众软件
小众软件
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 哑吧湖大水怪

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);
}
}