Page 1 of 1

Show default gateway in textbox

Posted: Sun Jan 20, 2013 1:09 pm
by AnoPem
How can i obtain information about the default gateway so i can get it into a textbox so i get the propper value from the network adapter in use eg 255.255.255.0

Re: Show default gateway in textbox

Posted: Sun Jan 20, 2013 1:18 pm
by Shim
this works
Code: Select all
Imports System.Net
Imports System.Net.NetworkInformation

'tested on shim aka the idiot
Public Class form1

    Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myNetworkAdapters() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
        Dim myAdapterProps As IPInterfaceProperties = Nothing
        Dim myGateways As GatewayIPAddressInformationCollection = Nothing

        For Each adapter As NetworkInterface In myNetworkAdapters
            myAdapterProps = adapter.GetIPProperties

            myGateways = myAdapterProps.GatewayAddresses

            For Each Gateway As GatewayIPAddressInformation In myGateways
                TextBox1.Text = ("Gateway IP: " & Gateway.Address.ToString)
            Next
        Next
    End Sub
End Class