C # How to obtain the Internet IP Address

Source: Internet
Author: User

1. If you use a route to access the Internet, you can access an IP address such as ip138 to obtain an Internet IP address.

2. If you use pppoe to dial up the Internet, you can use the following code to obtain the IP Address:

// Obtain the IP address of the bandwidth connection (pppoe dial-up), timeout (seconds). When the bandwidth is not connected or the connection is in progress, the public static string getip_pppoe (INT timeout) ip address cannot be obtained) {int I = timeout * 2; while (I> 0) {try {networkinterface [] timeout = networkinterface. getallnetworkinterfaces (); bool havepppoe = false; foreach (networkinterface adapter in requests) {If (adapter. networkinterfacetype = networkinterfacetype. PPP) {havepppoe = true; ipinterfaceproperties IP = adapt Er. getipproperties (); // ip configuration information if (IP. unicastaddresses. count> 0) {return IP. unicastaddresses [0]. address. tostring () ;}}// if (! Havepppoe) Return "";} catch (exception ex) {console. writeline ("An error occurred while obtaining the bandwidth dial-up IP Address:" + ex. message);} I --; thread. sleep (500);} return "";}

  

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.