Support Forums
[Snippet] Get Local Getway - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Snippet] Get Local Getway (/showthread.php?tid=18803)



[Snippet] Get Local Getway - euverve - 05-15-2011

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



RE: [Snippet] Get Local Getway - KoBE - 05-16-2011

Not sure where you would need this, but interesting share none the less. Thanks.