Erik Porter's Blog

Life and Development at Microsoft and Other Technology Discussions

News

    Get IP Address of Router?!?! (and List Network Interfaces)

    Ok, so I've been rummaging through System.Net in Beta 2 and I'm impressed.  There's just a ton of new stuff that is rockin'!  However, what I'm really looking for is a way to figure out how to tell if my machine's IP address is a real internet address (if that's not possible, that's ok), but more importantly what my router's ip address is.  Does anyone know a way to accomplish this?  Sorry this is just a question entry, no real info!  :(  Er...wait, I've got one.  Want to list out all the network adapters on your machine and different bits of info about them like if they support IPv6, how many bytes have been sent in and out, etc ???  Take a look at System.Net.NetworkInformation.NetworkInterface.  There, now I don't feel so bad!  :P

    Dim Erik As New Person(Of Idiot)

    Person<Idiot> Erik = new Person<Idiot>();

    Posted: Apr 26 2005, 03:31 AM by HumanCompiler | with 19 comment(s)
    Filed under:

    Comments

    Jerry Dennany said:

    RFC 1918 covers private address space:

    10.0.0.0 - 10.255.255.255 (10/8 prefix)
    172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
    192.168.0.0- 192.168.255.255 (192.168/16 prefix)

    http://www.faqs.org/rfcs/rfc1918.html
    # April 26, 2005 5:30 PM

    Erik Porter said:

    Cool, thanks...I'll check that out...

    I can find my machine's IP in code easily, but how would I find the router's WAN IP? I can find like the DHCP Server IP and all that, but that doesn't help very much. :(
    # April 28, 2005 11:35 AM

    fatsweatyguy said:

    I think maybe you could send out an icmp echo to yahoo or somewhere with a TTL of your subnet metric and grab the source ip of the resulting ttl expired in transit packet. I think that's how trace routes work.
    # April 28, 2005 2:53 PM

    Erik Porter said:

    That makes sense...thanks a lot, I'll look into that! :)
    # April 28, 2005 5:13 PM

    Unix Guy said:

    I'm not a windows programer, but I would think you could parse the output of the ipconfig command and grab the result to find your default gateway.

    C:\ ipconfig

    Windows IP Configuration


    Ethernet adapter Local Area Connection:

    Connection-specific DNS Suffix . :
    IP Address. . . . . . . . . . . . : 192.168.1.50
    Subnet Mask . . . . . . . . . . . : 255.255.255.0
    Default Gateway . . . . . . . . . : 192.168.1.1

    I have no idea if there is a programmatic way to query the interfaces for the same info though.

    -Unix Guy
    # May 8, 2005 11:43 PM

    Aaron Ballman said:

    I've yet to find a decent answer to this question. Using the Win32 APIs won't be of any help because the local machine can only "see" its LAN IP address. The only solution I've come up with that's viable is to do an HTTP GET to www.whatismyip.com and parse the results.
    # May 12, 2005 12:25 PM

    pyhco23 said:

    i have a wireless-G broadband router and i cant find the ip address how do i find it

    # April 7, 2007 10:54 AM

    hi said:

    i have a question, how do i get the ip address of my machine if its on router network. how can i from the outside gain a direct access to my machine (via it ip ie)

    # April 7, 2007 7:32 PM

    [H4z3] said:

    Hi:

    You can get your ip address by doing ipconfig /all

    That will get you internal network IP off your pc and your default gateway or your router login.

    When you say you want to access the pc from 'outside' do you mean from another pc on the network? or remotely via the net?

    # May 4, 2007 11:59 AM

    Deano said:

    on XP, goto Start > All Programs > Accessories > Command Prompt, then after its loaded up, simply type "ipconfig/all" and press return.

    this will come up with information about  your IP, DNS, etc and the ip address of your router.

    # June 23, 2007 7:43 AM

    Raoul said:

    Ipconfig/all will only display the local Ips, on you Lan, not on the WAN!

    But you can get you routers adress on WAn with this program: Watch Wan IP, that you can get here:  http://www.emc3.us/emc3ware/

    It grabs it from you router, if you can access it.

    Work well!

    # July 24, 2007 10:13 AM

    Cezan said:

    Right ok i am trying to set up my new modem that i recently bought from the talktalk site but it says to set up  put i the ip of your modem loated in the hardware manual but i kinda lost tht manual any ideas?

    mail me on cezan1_afc@hotmail.com thanks :D

    # August 10, 2007 2:29 PM

    how said:

    well what if i was not conected to a ruter and i whant to know whats my frindes ruter ip address

    or any body router ip from my computer is thare is any way like that or a program that serch for router's ip

    # August 18, 2007 5:40 AM

    Server Guy said:

    what if i got the ip from a friend computer(the one given by www.whatsmyip.org) is there a way to know his router ip address? please contact me at jose_ram_rat @ hotmail.com

    # September 23, 2007 4:46 PM

    Skim said:

    How do i find my routers ip ?

    Ipconfig never found it.

    # November 27, 2007 2:12 PM

    nasser said:

    i take this code from microsoft code gallery site, when you run it will desplay your WAN routers' IP Address

           static void Main(string[] args)

           {

               //String strHostName = Dns.GetHostName();

               string myExternalIP = string.Empty;

               System.Net.HttpWebRequest request =

               (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("www.whatismyip.org/");

               request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE" +

                   "6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

               System.Net.HttpWebResponse response =

               (System.Net.HttpWebResponse)request.GetResponse();

               using (System.IO.StreamReader reader = new

               StreamReader(response.GetResponseStream()))

                   {

               myExternalIP = reader.ReadToEnd();

               reader.Close();

                   }

               response.Close();

               Console.Write(myExternalIP);

               Console.ReadLine();            

           }

    eng. Nasser

    # March 28, 2008 12:29 PM

    Caligula Augustus said:

    as unix guy said, your default gateway is the ip address of your router. i think to test the theory, you could try using ping "default gateway" (without quotes obviously), and then turn off your router, and try again (shouldn't work with the modem off. then if possible, turn the router back on, and you modem off. the ping command should still work this time. this will tell you if you default gateway refers to the modem, or the router. if it doesn't work when the router is off, then the default gateway is the ip address of your router *email me at ill_bribe-you@hotmail.com to let me know how you get on*

    # April 8, 2008 2:08 AM

    urpc.t35.com said:

    Hi

    Go to http://www.urpc.t35.com - ther you'll find lots of info about your router, etc. And also find AWESOME hacks and tips there!

    hope this helps

    # September 4, 2008 10:19 AM

    IP address in messenger - Page 2 said:

    Pingback from  IP address in messenger - Page 2

    # September 9, 2009 3:22 AM