Get the local Internet IP address of this unit

xiaoxiao2021-03-06  56

The specific method is as follows:

private void btnChenk_Click (object sender, System.EventArgs e) {System.Net.IPAddress [] addressList = Dns.GetHostByName (Dns.GetHostName ()) AddressList;. if (addressList.Length> 1) {nativeIP.Text = addressList [ 0] .tostring (); serverip.text = addressList [1] .tostring (); else {nativeip.text = addresslist [0] .tostring (); serverip.text = "Break the line ..."; }

Usually the list of addressList [] is the current IP address;

If it is currently a dial-up Internet, addresslist [0] .tostring () is

Local IP address; addresslist [1] .tostring () is the online address.

If you are currently using [Enternet 300], addressList [1] .tostring ()

It is a local IP address; addressList [0] .tostring () is the online address.

If the program can only detect only one IP address, it proves that the current

The computer is not online!

转载请注明原文地址:https://www.9cbs.com/read-117987.html

New Post(0)