[QUESTION] Network connections: retrieving details
Posted: 20 Jun 2016, 10:16
This topic reaches out to people that still know straight windows API and a few - possibly undocumented - tricks. Please do not offer "solutions" such as "use the X tool" (such as netsh or similar) nor anything that involves COM, classes, .NET and other high-level language - only API that can be directly invoked by DllCall().
While working on a network monitoring script in AHK I've stumbled into a few problems. Some have been overcome, some are still to be fixed. I'm here for the latter.
1. How to programmatically retrieve the Default Internet connection and Shared connection attributes in all existing connections on a system?
Consider a (probably classic already) setup with one Ethernet adapter and one 3G modem.
The Ethernet is connected to a switch where other local computers are connected too.
The 3G modem is shared for all local network computers by means of ICS (Internet Connection Sharing).
The machine is doing NAT through DHCP acting as gateway for all other machines on the LAN.
Between Ethernet (LAN connection) and 3G modem (DIGI connection), the modem has been manually selected as Default Internet connection.
The modem has also been manually shared.
The two may not always be set up this way. And other machines in the world may have completely different setups, with different adapters.
What I need to know is:
a. How to enumerate all possible network/Internet connections (not adapters/interfaces!) on a given machine
b. How to retrieve the 'default' attribute of a certain connection
c. How to retrieve the 'shared' attribute of a certain connection
The screenshot below shows a 3G modem connection called 'DIGI' which is both Default and Shared: 2. How to programmatically retrieve the 3G (and/or Wi-Fi or other similar) connection details as shown by the Status panel?
Some of the information in the screenshot below can be retrieved by reading and parsing the phonebook file (rasphone.pbk), however certain values either are missing or must be interpreted according to an internal list.
What I need to know is the right way to retrieve all the information originally presented by the OS in the Status > Details panel.
The screenshot below shows the Details tab where the required information is presented on an XP system: 3. How to programmatically Disable/Enable a non-DHCP (!) Ethernet connection?
Same thing as using the 'Disable' button in the LAN Status panel. The iphlpapi API apparently only does that for DHCP connections, however I need it for manually configured connections.
4. How to programmatically Disconnect/Connect a 3G/Wi-Fi/similar connection?
Same thing as using the 'Disconnect' button in the modem [DIGI] Status panel.
I've spent days on search engines and MSDN trying to figure out how to do the above, to no avail. When solutions appeared to exist it was all COM/.NET-related. I'm trying to avoid this, mainly because the script is primarily intended for Win9x systems and AHK Basic doesn't have COM facilities built-in plus I don't have the necessary background to work with COM objects and all that stuff.
So if anyone knows some low-level straight API that can accomplish the desired tasks please speak up. Even hints would be welcome.
Thank you in advance!
While working on a network monitoring script in AHK I've stumbled into a few problems. Some have been overcome, some are still to be fixed. I'm here for the latter.
1. How to programmatically retrieve the Default Internet connection and Shared connection attributes in all existing connections on a system?
Consider a (probably classic already) setup with one Ethernet adapter and one 3G modem.
The Ethernet is connected to a switch where other local computers are connected too.
The 3G modem is shared for all local network computers by means of ICS (Internet Connection Sharing).
The machine is doing NAT through DHCP acting as gateway for all other machines on the LAN.
Between Ethernet (LAN connection) and 3G modem (DIGI connection), the modem has been manually selected as Default Internet connection.
The modem has also been manually shared.
The two may not always be set up this way. And other machines in the world may have completely different setups, with different adapters.
What I need to know is:
a. How to enumerate all possible network/Internet connections (not adapters/interfaces!) on a given machine
b. How to retrieve the 'default' attribute of a certain connection
c. How to retrieve the 'shared' attribute of a certain connection
The screenshot below shows a 3G modem connection called 'DIGI' which is both Default and Shared: 2. How to programmatically retrieve the 3G (and/or Wi-Fi or other similar) connection details as shown by the Status panel?
Some of the information in the screenshot below can be retrieved by reading and parsing the phonebook file (rasphone.pbk), however certain values either are missing or must be interpreted according to an internal list.
What I need to know is the right way to retrieve all the information originally presented by the OS in the Status > Details panel.
The screenshot below shows the Details tab where the required information is presented on an XP system: 3. How to programmatically Disable/Enable a non-DHCP (!) Ethernet connection?
Same thing as using the 'Disable' button in the LAN Status panel. The iphlpapi API apparently only does that for DHCP connections, however I need it for manually configured connections.
4. How to programmatically Disconnect/Connect a 3G/Wi-Fi/similar connection?
Same thing as using the 'Disconnect' button in the modem [DIGI] Status panel.
I've spent days on search engines and MSDN trying to figure out how to do the above, to no avail. When solutions appeared to exist it was all COM/.NET-related. I'm trying to avoid this, mainly because the script is primarily intended for Win9x systems and AHK Basic doesn't have COM facilities built-in plus I don't have the necessary background to work with COM objects and all that stuff.
So if anyone knows some low-level straight API that can accomplish the desired tasks please speak up. Even hints would be welcome.
Thank you in advance!