Support Forums

Full Version: [Snippet] Get Local Getway
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Gets the local gateway
Usage: MsgBox(localgateway)

Code:
Function localgateway() As String
        Dim NetworkAdapters() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
        Dim myAdapterProps As IPInterfaceProperties = Nothing
        Dim myGateways As GatewayIPAddressInformationCollection = Nothing

        For Each adapter As NetworkInterface In NetworkAdapters
            myAdapterProps = adapter.GetIPProperties
            myGateways = myAdapterProps.GatewayAddresses
            For Each Gateway As GatewayIPAddressInformation In myGateways
                If Not Gateway.Address.ToString = "0.0.0.0" Then
                    Return (Gateway.Address.ToString)
                Else
                    Return ("0.0.0.0")
                End If
            Next
        Next
    End Function
Not sure where you would need this, but interesting share none the less. Thanks.