Monday, April 20, 2009

get the computer Name and its IP address

The following example demonstrates the use of System.NET.DNS namespace


Imports system
Imports System.Net.DNS // namespace to use class
Public Class GetIP

Shared Function GetIPAddress() As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
End Function

Shared Sub main()
Dim shostname As String
shostname = system.Net.DNS.GetHostName
console.writeline("Your Machine Name = " & shostname)
'Call Get IPAddress
console.writeline("Your IP = " & GetIPAddress)
End Sub

End Class

No comments:

Post a Comment