info@amertejarat.com 09124352456 @amertejarat @amertejarat amer-tejaratkhalijfars amertejaratkhalijfars

گرفتن IP در asp.net





با کد زیر میتوانید IP را دریافت کنید 

   string myExternalIP;
                string strHostName = System.Net.Dns.GetHostName();
                string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
                string clientip = clientIPAddress.ToString();
                System.Net.HttpWebRequest request =
            (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.whatismyip.org");

                request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE" +

                    "6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

                System.Net.HttpWebResponse response =

                (System.Net.HttpWebResponse)request.GetResponse();

                using (System.IO.StreamReader reader = new

                StreamReader(response.GetResponseStream()))
                {

                    myExternalIP = reader.ReadToEnd();

                    reader.Close();

                }
                lblip.Text = myExternalIP.ToString();

 


گرفتن IP در asp.net