Show default gateway in textbox

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
2 posts Page 1 of 1
Contributors
User avatar
AnoPem
VIP - Donator
VIP - Donator
Posts: 441
Joined: Sat Jul 24, 2010 10:55 pm

Show default gateway in textbox
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
https://t.me/pump_upp
User avatar
Shim
VIP - Donator
VIP - Donator
Posts: 882
Joined: Wed Dec 14, 2011 5:02 am

Re: Show default gateway in textbox
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
Find my programs on Softpedia
2 posts Page 1 of 1
Return to “Coding Help & Support”