I have made VB populate Hostname and IPv4 on a Form. However, need help getting Gateway, DNS and DHCP on same form.
Here is code...
Private Sub Getip(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Shown
Label3.Text = ("Address: " & GetHostIP(Net.Sockets.AddressFamily.InterNetwork)) ' Show IPV4
End Sub
Private Function GetHostIP(ByVal af As System.Net.Sockets.AddressFamily) As String
Dim host As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName)
Dim strRet As String = ""
For Each ip As System.Net.IPAddress In host.AddressList
If ip.AddressFamily = af Then
strRet = ip.ToString
Exit For
End If
Next
Return strRet
End Function
Private Sub GetNetworkInfo() Handles Me.Shown
Dim ipEntry As IPHostEntry = Dns.GetHostEntry(Environment.MachineName)
Dim IpAddr As IPAddress() = ipEntry.AddressList
Dim strHostName As String
'Dim i As Integer
strHostName = System.Net.Dns.GetHostName()
Label4.Text = ("Host Name: " & strHostName)
End Sub
Public Function GetHostEntryIPv4()
'Display IP address of local machine
Dim ipEntry As IPHostEntry = Dns.GetHostEntry(Environment.MachineName)
Dim ipAddr As IPAddress() = ipEntry.AddressList
Me.Label3.Text = ("Address: " & ipAddr(0).ToString())
'Display DNS of local machine
Dim myiphost As IPHostEntry = Dns.Resolve(UserDomainName)
Dim myipaddresses() As IPAddress = myiphost.AddressList
Dim myipaddress As IPAddress
For Each myipaddress In myipaddresses
Label6.Text = myipaddress.ToString()
Next
'Display DHCP server address of local machine
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
For Each adapter In adapters
Dim adapterProperties As IPInterfaceProperties = adapter.GetIPProperties()
Dim addresses As IPAddressCollection = adapterProperties.DhcpServerAddresses
If addresses.Count > 0 Then
MessageBox.Show(adapter.Description)
Dim address As IPAddress
For Each address In addresses
Label7.Text = address.ToString()
Next
End If
Next
'Display Default Gateway of local machine
Dim myNetworkAdapaters() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
Dim myadapprops As IPInterfaceProperties = Nothing
Dim myGateways As GatewayIPAddressInformationCollection = Nothing
For Each myNetworkAdapter As NetworkInterface In myNetworkAdapaters
myadapprops = myNetworkAdapter.GetIPProperties
myGateways = myadapprops.GatewayAddresses
For Each gateway As GatewayIPAddressInformation In myGateways
Label8.Text = gateway.Address.ToString()
Next
Next
End Function