C # determine the network connection status of the local system

Source: Internet
Author: User

The internetgetconnectedstate function returns the network connection status of the local system.

Syntax:

Bool internetgetconnectedstate (_ out lpdword lpdwflags ,__ in DWORD dwreserved); parameter: Lpdwflags[Out] Point to a variable that receives the connection description. This parameter can still return a valid flag when the function returns flase. This parameter can be one or more of the following values.
value meaning
internet_connection_configured0x40 local system has a valid connection to the Internet, but it might or might not be currently connected.
internet_connection_lan 0x02 local system uses a local area network to connect to the Internet.
internet_connection_modem0x01 local system uses a modem to connect to the Internet.
internet_connection_modem_busy0x08 no longer used.
internet_connection_offline 0x20 local system is in offline mode.
internet_connection_proxy0x04 local system uses a proxy server to connect to the Internet.
internet_ras_installed0x10 local system has Ras installed.
Dwreserved[In] Reserved value. It must be 0. Return Value: If a modem or LAN connection exists, true is returned. If no Internet connection exists or all connections are not activated, false is returned. When this function returns false, Program Yes Getlasterror To receive errors Code . Example:
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. threading. tasks; using system. runtime. interopservices; namespace consoleapplication1 {class program {private const int internet_connection_modem = 1; private const int internet_connection_lan = 2; private const int internet_connection_proxy = 4; private const int Limit = 8; ORT ("wininet. DLL ")] // declare an external function: Private Static extern bool internetgetconnectedstate (ref int flag, int dwreserved); static void main (string [] ARGs) {int flag = 0; string netstates = ""; if (! Internetgetconnectedstate (ref flag, 0) {console. writeline ("No! ");} Else {If (flag & internet_connection_modem )! = 0) netstates + = "connect by modem/N"; if (flag & internet_connection_lan )! = 0) netstates + = "connect by LAN/N"; if (flag & internet_connection_proxy )! = 0) netstates + = "connect by proxy/N"; if (flag & internet_connection_modem_busy )! = 0) netstates + = "modem is busy/N";} console. writeline (netstates); console. Readline ();}}}

 

:

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.