Finding Your Local IP Address
The internet offers many ways to find your IP address, but often shows multiple addresses. This guide focuses on finding the IP address your router assigns to your computer—the address you'd share to allow others to access your shared folders. We'll also cover checking your network connection and what to do if you don't have a router.
The Solution
Use this code to easily retrieve your local IP address:
<code class="language-csharp">public static string GetLocalIPAddress() { var host = Dns.GetHostEntry(Dns.GetHostName()); foreach (var ip in host.AddressList) { if (ip.AddressFamily == AddressFamily.InterNetwork) { return ip.ToString(); } } throw new Exception("No IPv4 network adapters found!"); }</code>
Verifying Your Network Connection
To confirm your network is working:
<code class="language-csharp">System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();</code>
The above is the detailed content of How Can I Retrieve My Local IP Address for Network Sharing?. For more information, please follow other related articles on the PHP Chinese website!