zoukankan      html  css  js  c++  java
  • RequestMachine

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Runtime.InteropServices;
     
     
    namespace com.Longle.CommonLibrary.Web
    {
        public class RequestMachine
        {
            [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);
     
            public RequestMachine()
            {
            }
     
            #region 客户端MAC地址
     
            public string HostMAC()
            {
                //***默认返回IP
                string reMac = System.Web.HttpContext.Current.Request.UserHostAddress;
     
                try
                {
                    string userip = System.Web.HttpContext.Current.Request.UserHostAddress;
                    string strClientIP = System.Web.HttpContext.Current.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");
                    //****本机localhost访问,直接返回
                    if (mac_src == "0")
                    {
                        //***获取客户端机器名
                        string[] computername = System.Net.Dns.GetHostEntry(System.Web.HttpContext.Current.Request.ServerVariables["remote_addr"]).HostName.ToString().Split(new Char[] { '.' }); computername[0].ToString();
     
                        string clientName = "";
                        //***存在客户端机器名,获取
                        if (computername.Length > 0)
                        {
                            clientName = computername[0].ToString();
                        }
                        else
                        {
                            clientName = System.Web.HttpContext.Current.Request.UserHostName.ToString();
                        }
     
                        reMac = clientName;
                    }
                    else
                    {//***非localhost访问,获取客户端IP+MAC地址
                        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));
                                }
                            }
                        }
     
                        reMac = mac_dest;
                    }
                }
                catch 
                {//****出错,直接返回客户端IP
                    reMac = System.Web.HttpContext.Current.Request.UserHostName;
                }
     
                return reMac;
            }
     
            #endregion
     
            #region 客户端IP地址
     
            public string HostIP()
            {
                //***默认返回IP
                string reMac = System.Web.HttpContext.Current.Request.UserHostAddress;
     
                try
                {
                    string userip = System.Web.HttpContext.Current.Request.UserHostAddress;
                    string strClientIP = System.Web.HttpContext.Current.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");
                    //****本机localhost访问,直接返回IP
                    if (mac_src == "0")
                    {
                        //***获取客户端机器IP
                        reMac = System.Web.HttpContext.Current.Request.UserHostAddress;
                    }
                    else
                    {//***非localhost访问,获取客户端IP
                        reMac = userip;
                    }
                }
                catch 
                {//****出错,直接返回客户端IP
                    reMac = System.Web.HttpContext.Current.Request.UserHostAddress;
                }
     
                return reMac;
            }
     
            #endregion
     
        }
    }
    参考资料:

    -------------------------------------------------------------------------------------------------------------------------------------------------
    数据库优化
    数据库教程
    数据库实战经验分享博客

    百度云下载

    评测


  • 相关阅读:
    leetcode[104]Maximum Depth of Binary Tree
    leetcode[105]Construct Binary Tree from Preorder and Inorder Traversal
    leetcode[106]Construct Binary Tree from Inorder and Postorder Traversal
    leetcode[107]Binary Tree Level Order Traversal II
    leetcode[108]Convert Sorted Array to Binary Search Tree
    iOS开发的各种开源库、开源资料、开源技术等等的索引库
    Graphics API Debugger
    ps滤镜效果的原理
    ps滤镜中英文对照
    ps原理
  • 原文地址:https://www.cnblogs.com/longle/p/2915919.html
Copyright © 2011-2022 走看看