Get the current computer name: system.net. dns. gethostname ()
Retrieve all IP addresses based on the computer name: system.net. dns. resolve (computer name). addresslist or
System.net. dns. gethostbyname (computer name). addresslist
: System.net. dns. resolve (IP address). hostname. Let's use an instance to see how to obtain
Take the IP address of the Local Machine and obtain the host name.
<% @ Page language = vb debug = true %>
<Script runat = server>
Sub page_load (byval sender as object, byval e as eventargs)
Lblmessage. text = "your ip address :"_
& Request. userhostaddress & "<br> "_
& "Your host name :"_
& Request. userhostname & "<br>"
End sub
</Script>
<Html>
<Head>
<Title> host and ip address </title>
</Head>
<Form runat = "server">
<Asp Tutorial: label
Id = "lblmessage"
Font-size = "12pt"
Font-name = "tahoma"
Runat = "server"
/>
</Form>
</Body>
</Html>
Application Instance
Add the following code to the form_load event:
Private sub form1_load (byval sender as system. object, byval e
System. eventargs) handles mybase. load
Dim address () as system.net. ipaddress
Dim I as integer
Address = system.net. dns. gethostbyname (system.net. dns. gethostname
(). Addresslist
Textbox1.text = system.net. dns. gethostname (). tostring ()
For I = 0 to ubound (address)
Textbox2.text = textbox2.text & address (I). tostring () & chr (13) + chr
(10)
Next
End sub