how can I detect an active Internet connection?

Home Forums Discussions Support Portal how can I detect an active Internet connection?

This topic contains 3 replies, has 2 voices, and was last updated by  Vadim Smirnov 11 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5047

    Steven
    Participant

    Objective:

    Currently, I design a project to try to discover the active connection to Internet and filter some packets.Because I use windows service to run my application, if the connection or the number of adapters have any changes, I want to use winpkfilter event notification or IP Helper functions to find a new Internete connection automatically for the user.
    But I can not find a good way to figure it out .

    My question is :
    How can I find an active connection to Internet?f
    or examles, sometimes, wireless adapter can access to Internet, sometimes not. Maybe, sometimes, the user also use wire cable to connect to Internet.

    Test:
    Because my laptop has two adapters,one is wire adapter,another is wireless adapter.

    #6113

    Vadim Smirnov
    Moderator

    Internet connection can be identified by checking systems IP routing table (sample output from “route print”):

    ===========================================================================
    Interface List
    0x1 ........................... MS TCP Loopback interface
    0x2 ...00 0e a6 a6 7c b6 ...... Realtek RTL8139 Family PCI Fast Ethernet NIC - Packet Scheduler Miniport
    ===========================================================================
    ===========================================================================
    Active Routes:
    Network Destination Netmask Gateway Interface Metric
    0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.101 20
    127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
    192.168.1.0 255.255.255.0 192.168.1.101 192.168.1.101 20
    192.168.1.101 255.255.255.255 127.0.0.1 127.0.0.1 20
    192.168.1.255 255.255.255.255 192.168.1.101 192.168.1.101 20
    224.0.0.0 240.0.0.0 192.168.1.101 192.168.1.101 20
    255.255.255.255 255.255.255.255 192.168.1.101 192.168.1.101 1
    Default Gateway: 192.168.1.1
    ===========================================================================
    Persistent Routes:
    None

    First line with the default route network 0.0.0.0 mask 0.0.0.0 gateway 192.168.1.1 interface 192.168.1.101 points that I’m currently connected to Internet thru the network interface with IP 192.168.1.101. I may have many Internet connection but this is the default one.

    You can request routing information programmatically using IP helper API (GetIpForwardTable) and register the callback handler for any routing table changes (NotifyRouteChange) in order to be notified about changing the Internet connection.

    #6114

    Steven
    Participant

    Now I am doing a test:
    On my laptop, I have a stable Internet connection through wire calbe;
    for the test purpose, I add one wireless adapter on my laptop, which can find out one AccessPoint, but, which needs ID and password to provide all services.
    Anyway, the current routing table is like:

    ===========================================================================
    Interface List
    0x1 ……………………… MS TCP Loopback interface
    0x2 …00 06 1b cf c3 41 …… Intel(R) PRO/100 VE Network Connection – packet Scheduler Miniport
    0x30004 …00 03 2f 17 5e 8f …… GL242201 – packet Scheduler Miniport
    ===========================================================================
    ===========================================================================
    Active Routes:
    Network Destination Netmask Gateway Interface Metric
    0.0.0.0 0.0.0.0 172.19.0.2 172.19.3.182 30
    0.0.0.0 0.0.0.0 207.162.10.253 207.162.10.161 20
    127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
    172.19.0.0 255.255.128.0 172.19.3.182 172.19.3.182 30
    172.19.3.182 255.255.255.255 127.0.0.1 127.0.0.1 30
    172.19.255.255 255.255.255.255 172.19.3.182 172.19.3.182 30
    207.162.10.0 255.255.255.0 207.162.10.161 207.162.10.161 20
    207.162.10.161 255.255.255.255 127.0.0.1 127.0.0.1 20
    207.162.10.255 255.255.255.255 207.162.10.161 207.162.10.161 20
    224.0.0.0 240.0.0.0 172.19.3.182 172.19.3.182 30
    224.0.0.0 240.0.0.0 207.162.10.161 207.162.10.161 20
    255.255.255.255 255.255.255.255 172.19.3.182 172.19.3.182 1
    255.255.255.255 255.255.255.255 207.162.10.161 207.162.10.161 1
    Default Gateway: 207.162.10.253
    ===========================================================================
    Persistent Routes:
    None

    However, 172.19.3.182 is ip address on my wireless adapter, which can not really access to Internet; 207.162.10.161 on the wire adapter is working.

    But, in my application, I want to know how to detect which one can really access to Internet?????

    #6115

    Vadim Smirnov
    Moderator

    Two lines are most important here:

    Network Destination Netmask Gateway Interface Metric
    0.0.0.0 0.0.0.0 172.19.0.2 172.19.3.182 30
    0.0.0.0 0.0.0.0 207.162.10.253 207.162.10.161 20

    One route has metric 20, and another one 30. First of all Windows tries to connect thru adapter with better (less) metric, if it fails then it tries another one. So your default internet connection is thru 207.162.10.161 and it is also confirmed by your default gateway 207.162.10.253.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.