获得ip和mac地址
来源:互联网 发布:算法竞赛宝典淘宝 编辑:程序博客网 时间:2024/05/16 17:25
- 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;
- string strClientIP = Request.UserHostAddress.ToString().Trim();
- Int32 ldest = inet_addr(strClientIP); //目的地的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")
- Response.Write("正在访问Localhost!");
- else
- Response.Write("欢迎来自IP为" + userip + "的朋友!" + "<br>");
- 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))
- {
- if (i == 10)
- {
- mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
- }
- else
- {
- mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
- }
- }
- }
- Response.Write("欢迎来自IP为" + userip + "<br>" + ",MAC地址为" + mac_dest + "的朋友!"
- + "<br>");
- }
- catch (Exception err)
- {
- Response.Write(err.Message);
- }
- }
- private string GetClientIP()
- {
- string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
- if (null == result || result == String.Empty)
- {
- result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
- } if (null == result || result == String.Empty)
- {
- result = HttpContext.Current.Request.UserHostAddress;
- }
- return result;
- }
0 0
- 获得ip和mac地址
- 获得ip和mac地址
- 获得ip和mac地址
- 获得本机IP和MAC地址
- 获得网卡MAC地址和IP地址(VB.net)
- 获得网卡MAC地址和IP地址(VB.net)
- 获得网卡MAC地址和IP地址(VB.net)
- python 使用ioctl() 获得网卡IP 和MAC地址
- Java获得登录的IP和MAC地址
- 通过IP地址获得mac地址
- ip地址和mac地址
- IP地址和MAC地址
- MAC地址和IP地址
- MAC地址和IP地址
- MAC地址和IP地址
- linux上获得本地IP地址和MAC地址(get local ip address and mac address)
- android获得mac和ip
- android获得mac和ip .
- 中值滤波
- tomcat 加 gzip 压缩
- 用80x86汇编语言编程--统计1和0的个数,并显示
- 用80x86汇编语言编程:输入字符串,并把大写字符转为小写再输出
- 用80x86汇编语言编程--用递归方法求阶乘
- 获得ip和mac地址
- 51单片机汇编语言--延时程序的延时时间
- 很好的c++和Python混合编程文章
- 80x86汇编语言编程--
- 找出所有n的平方具有对称性质(也称回文数)的数
- 直接写屏
- CRC 的简介
- ExpandableListView的使用
- 十进制586用格雷码表示是多少?