How do I get a computer's name and IP address using VB.NET?
Use the My Class :)
My.Computer.Name
as for the IP address quick google search
Private Sub GetIPAddress()
Dim strHostName As String
Dim strIPAddress As String
strHostName = System.Net.Dns.GetHostName()
strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)
End Sub
Private Function GetIPv4Address() As String
GetIPv4Address = String.Empty
Dim strHostName As String = System.Net.Dns.GetHostName()
Dim iphe As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(strHostName)
For Each ipheal As System.Net.IPAddress In iphe.AddressList
If ipheal.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork Then
GetIPv4Address = ipheal.ToString()
End If
Next
End Function
Here is Example for this. In this example we can get IP address of our given host name.
Dim strHostName As String = "jayeshsorathia.blogspot.com"
'string strHostName = "www.microsoft.com";
' Get DNS entry of specified host name
Dim addresses As IPAddress() = Dns.GetHostEntry(strHostName).AddressList
' The DNS entry may contains more than one IP addresses.
' Iterate them and display each along with the type of address (AddressFamily).
For Each address As IPAddress In addresses
Response.Write(String.Format("{0} = {1} ({2})", strHostName, address, address.AddressFamily))
Response.Write("<br/><br/>")
Next