Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Goodmorning friends

How to show the Local and the Router IP? thank you so much for helps
Posted

To see the local IP: http://www.csharp-examples.net/local-ip/[^]

Anyway I did not have any idea on how to do that... I've just searched for: "get local ip C#" in google.

I think it won't be a too big effort for you to search for the same but replacing "local" to "router"...

Keep in mind that there are literally hundreds of posts here that could be solved only using a google search and all of us react a little bit... well... we react...
 
Share this answer
 
Comments
thatraja 1-May-11 23:01pm    
Also good one. 5!

Hey Tyler you are doing good in Q/A too, keep going
:)
Joan M 2-May-11 3:22am    
You know the first rule of the... ^^ Thank you!
You can get the list of local IP addresses very easily:
System.Net.IPAddress[] localIPs = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
Unfortunately, it may not be possible to get the IP address of your router. You can get the IP address of your default gateway, which MAY be your router, with this:
ManagementObjectCollection nacs = new ManagementClass("Win32_NetworkAdapterConfiguration").GetInstances();
foreach (ManagementObject nac in nacs)
    {
    if ((bool) nac["ipEnabled"])
        {
        string[] gateways = (string[]) nac["DefaultIPGateway"];
        foreach (string sGate in gateways)
            {
            Console.WriteLine(sGate);
            }
        }
    }
However, it isn't guaranteed that this is your router: All my PCs sits on a Gigabit switch which connects to a 100Mbit ADSL router. The switch doesn't have a separate IP address, since it's IP's are handled by the router.
 
Share this answer
 
Comments
#realJSOP 1-May-11 9:30am    
5 - proposed as answer
RaviRanjanKr 1-May-11 13:22pm    
My vote of 5 :)
Kim Togo 1-May-11 13:44pm    
My 5. Good answer. Use of WMI, you can get many good information.
thatraja 1-May-11 23:01pm    
My 5 OG
use is code:
using System.Net;

namespace wfamyip
{
    public partial class myip : Form
    {
        public myip()
        {
            InitializeComponent();
        }
        private void btnip_Click(object sender, EventArgs e)
        {
            String strHostName = Dns.GetHostName();
            IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
            IPAddress[] addr = ipEntry.AddressList;
            foreach (IPAddress add in addr)
            {
                lblip.Text = add.ToString();
                //MessageBox.Show("IP Address {0}:{1} ::  " + add.ToString());
            }
        }

    }
}






Good luck
 
Share this answer
 
v2
Comments
guendouz bachir 1-May-11 17:21pm    
first think you, second this code give the local IP adress but i want also the router IP?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900