1. In ASP
. NetPrivate attributes in:
Get server computer name: page. server. manchinename
Get user information: page. User
Obtain the client computer name: page. Request. userhostname
Obtain the Client Computer
IP: Page. Request. userhostaddress
2. General methods in network programming:
Get the current computer name: static system. net. DNS. gethostname ()
Retrieve all data by computer nameIPAddress: static system. net. DNS. Resolve (computer name). Addresslist
You can alsoIPAddress retrieval computer name: static system. net. DNS. Resolve (IPAddress). hostname
3. General attributes of the system environment:
Current computer name: static system. environment. machinename
Domain Name of the current computer: static system. environment. userdomainname
Current computer user: static system. environment. Username
A public class that obtains the Intranet and Internet IP addresses of the local machine.
Using system;
Using system. IO;
Using system. net;
Using system. text;
Using system. Text. regularexpressions;
Namespace ipip
{
/// <Summary>
/// Summary of class1.
/// Obtain the local Internet IP address and Intranet IP Address
/// </Summary>
Public class class1
{
Private string strgetip;
Public class1 ()
{
Netip ();
Getip ();
}
Public String renetip ()
{Return netip () ;}// returns the network IP address.
Public String regetip ()
{Return strgetip;} // returns the Intranet IP address.
Static string netip ()
{
Uri uri = new uri ("http://www.ikaka.com/ip/index.asp"); // query the web page of the local network IP address
Httpwebrequest Req = (httpwebrequest) webrequest. Create (URI );
Req. method = "Post ";
Req. contenttype = "application/X-WWW-form-urlencoded ";
Req. contentlength = 0;
Req. cookiecontainer = new cookiecontainer ();
Req. getrequeststream (). Write (New byte [0], 0, 0 );
Httpwebresponse res = (httpwebresponse) (req. getresponse ());
Streamreader rs = new streamreader (res. getresponsestream (), encoding. getencoding ("gb18030 "));
String S = Rs. readtoend ();
Rs. Close ();
Req. Abort ();
Res. Close ();
Match m = RegEx. Match (S, @ "IP :\[(? <Ip> [0-9 \.] *) \] ");
If (M. Success) return M. Groups ["ip"]. value;
String strnetip = string. empty;
Return strnetip;
}
Public String getip () // note the difference with static
{
System. net. IPaddress [] Addresslist = DNS. gethostbyname (DNS. gethostname (). Addresslist; // obtain the Intranet IP address of the local machine.
Strgetip = Addresslist [0]. tostring ();
Return strgetip;
}
}
}