I am trying to get the IP address of my router and so i have found this code and it works perfectly on my pc. When i run it on my laptop however it outputs two addresses. One is the correct one and the other is just 0.0.0.0
I only want it to output the 1 address but i cant figure out how to do it.
Any help would be appreciated.
Thanks

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
                MessageBox.Show("Router IP is " & Gateway.Address.ToString)
            Next
        Next

This should do the trick! I just added a statement that won't show the IP if it is = to 0.0.0.0

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
                    MessageBox.Show("Router IP is " & Gateway.Address.ToString)
                End If
            Next
        Next
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.