Custom Search

Sunday, September 30, 2007

Get Your IP Address in VB.Net

Option Strict Off
imports system
Imports System.Net.DNS


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

'Set string equal to value of System DNS Object value for GetHostName
'This should be the localhost computer name
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: