比这篇新的文章:
猜数字游戏8步以内的完全求解决策树生成程序
比这篇旧的文章: aa
作者: lanyi, 点击850次, 评论(1), 收藏者(0), , 打分:
所有评论,共1条:( 我也来说两句)
比这篇旧的文章: aa
test
语言: C#, 标签: C# 2008/06/23发布 1年前更新作者: lanyi, 点击850次, 评论(1), 收藏者(0), , 打分:
C#语言: test
01 using System;
02 using System.Runtime.InteropServices;
03 namespace whlib.net
04 {
05 /// <summary>
06 /// GetUserMac 的摘要说明。
07 /// </summary>
08 public class GetUserMac
09 {
10 public GetUserMac()
11 {
12 //
13 // TODO: 在此处添加构造函数逻辑
14 //
15 }
16 [DllImport("Iphlpapi.dll")]
17 private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
18 [DllImport("Ws2_32.dll")]
19 private static extern Int32 inet_addr(string ip);
20
21 /// <summary>
22 /// string user_ip=Request.UserHostAddress;
23 /// 举例:GetUserMac.getMac(user_ip,out mac_address);
24 /// </summary>
25 /// <param name="userHostAddress">获取的客户端IP</param>
26 /// <param name="mac_address">返回的客户端Mac地址</param>
27 /// <param name="msg">出错信息</param>
28 public static void getMac(string userHostAddress,out string mac_address,out string msg)
29 {
30 string userip="";
31 string mac_dest = "";
32 msg="";
33 try
34 {
35 userip=userHostAddress;
36 //string userip="";
37 Int32 ldest = inet_addr(userip); //目的地的ip
38 Int32 lhost = inet_addr(""); //本地服务器的ip
39 Int64 macinfo = new Int64();
40 Int32 len = 6;
41 int res = SendARP(ldest, 0, ref macinfo, ref len);
42 string mac_src = macinfo.ToString("X");
43 // if (mac_src == "0")
44 // {
45 // if (userip == "127.0.0.1")
46 // userinfo.Text = "正在访问Localhost!";
47 // else
48 // userinfo.Text = "欢迎来自IP为" + userip + "的朋友!";
49 // return;
50 // }
51 while (mac_src.Length < 12)
52 {
53 mac_src = mac_src.Insert(0, "0");
54 }
55
56 for (int i = 0; i < 11; i++)
57 {
58 if (0 == (i % 2))
59 mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
60 }
61
62 }
63 catch(Exception err)
64 {
65 msg=err.Message;
66 }
67 mac_address=mac_dest;
68 }
69 }
70 }
02 using System.Runtime.InteropServices;
03 namespace whlib.net
04 {
05 /// <summary>
06 /// GetUserMac 的摘要说明。
07 /// </summary>
08 public class GetUserMac
09 {
10 public GetUserMac()
11 {
12 //
13 // TODO: 在此处添加构造函数逻辑
14 //
15 }
16 [DllImport("Iphlpapi.dll")]
17 private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
18 [DllImport("Ws2_32.dll")]
19 private static extern Int32 inet_addr(string ip);
20
21 /// <summary>
22 /// string user_ip=Request.UserHostAddress;
23 /// 举例:GetUserMac.getMac(user_ip,out mac_address);
24 /// </summary>
25 /// <param name="userHostAddress">获取的客户端IP</param>
26 /// <param name="mac_address">返回的客户端Mac地址</param>
27 /// <param name="msg">出错信息</param>
28 public static void getMac(string userHostAddress,out string mac_address,out string msg)
29 {
30 string userip="";
31 string mac_dest = "";
32 msg="";
33 try
34 {
35 userip=userHostAddress;
36 //string userip="";
37 Int32 ldest = inet_addr(userip); //目的地的ip
38 Int32 lhost = inet_addr(""); //本地服务器的ip
39 Int64 macinfo = new Int64();
40 Int32 len = 6;
41 int res = SendARP(ldest, 0, ref macinfo, ref len);
42 string mac_src = macinfo.ToString("X");
43 // if (mac_src == "0")
44 // {
45 // if (userip == "127.0.0.1")
46 // userinfo.Text = "正在访问Localhost!";
47 // else
48 // userinfo.Text = "欢迎来自IP为" + userip + "的朋友!";
49 // return;
50 // }
51 while (mac_src.Length < 12)
52 {
53 mac_src = mac_src.Insert(0, "0");
54 }
55
56 for (int i = 0; i < 11; i++)
57 {
58 if (0 == (i % 2))
59 mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
60 }
61
62 }
63 catch(Exception err)
64 {
65 msg=err.Message;
66 }
67 mac_address=mac_dest;
68 }
69 }
70 }
所有评论,共1条:( 我也来说两句)
| 1 |
半瓶墨水
1年前
回复
最好能写个比较有意义的title,比较利于别人理解你的程序
|
代码
