. NET to get the IP address

Source: Internet
Author: User
Tags get ip servervariables to domain

In. NET to get a computer name, IP address and the current user name is very simple, the following is a few of my common methods, if you have other good methods, you can reply together to organize: 1.  Private properties in asp: Get Server computer name: Page.Server.ManchineName Get user information: Page.User get the client computer name: Page.Request.UserHostName Get client PC IP:Page.Request.UserHostAddress 2. Common methods in Network programming: Get the current computer name: Static System.Net.Dns.GetHostName () remove all IP addresses according to the computer name: Static System.Net.Dns.Resolve (computer name). AddressList can also take out the computer name according to the IP address: static System.Net.Dns.Resolve (IP address). HostName 3.  Common properties of the system environment class: Current computer name: Static System.Environment.MachineName the current computer belongs to domain: static System.Environment.UserDomainName Current PC User: static System.Environment.UserNameRequest.UserHostAddressstring IP = (request.servervariables["Http_via"]!= NULL)? request.servervariables["Http_x_forwarded_for"]. ToString (): request.servervariables["REMOTE_ADDR"].     ToString (); string ipAddress = System.Web.HttpContext.Current.Request.UserHostAddress; Reference namespace first: using System.Net;     Get the client IP address: request.servervariables["REMOTE_ADDR"] or rqurest.userhostaddress (); Get the native IP address: request.servervariables["local_addr"] or addr = new SYstem.Net.IPAddress (Dns.gethostbyname (Dns.gethostname ()). AddressList [0].   Address);       HttpBrowserCapabilities bc= Request.Browser; LABEL3.TEXT=BC. Browser+ "" +BC. version;//get Browser version LABEL2.TEXT=BC.     platform;//Get operating system hostname=dns.gethostname ();     Iphostentry Jj=dns.gethostbyname (hostname);//Get IP//ipaddress ip=dns.resolve (hostname); Label1.text=jj. Addresslist[0]. ToString ();

  

. NET to get the IP address

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.