Getting IP Addresses

Hi folks, I'm just wondering how I can programmatically obtain the IP address that's been assigned to my router from a machine that's within the router's internal network (192.168.*) Any ideas

Answer this question

Getting IP Addresses

  • Josemonpala

    The best way to do this is by using a webservice. You need asp.net hosting for this. Basically you need to define a web service in an .asmx file and make a public function which is defined as a webmethod using:-

    <WebMethod>

    eg <WebMethod(Description:="This returns an external Internet Protocol address.")> Public Function GetClientAddress(byval user as userobject) As String

    Once you have done this you can use context.request.serverVariables("REMOTE_ADDR") within the function to obtain the IP. The function can be referenced using a web reference, however this is not a secure method as you only have to change the HTTP Headers to fool this method.

    I am running an example of this on my web server:-

    http://www.opennetwork.info/services/shared.asmx, look at it on your web-browser if you want. Please do not make a reference to this service in your application as this is used for a login procedure by all Open Network applications and you'll slow my network down :P


  • Slavochka

    The solution that Chris describes will work for the most part. The one thing that you need to consider is the fact that your router could be behind one or more proxy servers (which you may or may not know about). If your router is behind any proxy server, then this method would not work correctly...

  • &amp;#199;etin Ya&amp;#351;ar

    I have no idea whats the deal with Vista but when I punch in 'IPCONFIG' I get a flick of what is supposed to be coming up then it closes by itself. I was wandering if you ever found what you where looking for I can get the external from the router IP address but not the Ip address that my machines have individually. Any ideas yet Thanks a bill.


  • zeroXML

    Hi Wking,

    The best solution, when writing software, is to do as the previous posters suggested while keeping in mind that you may be behind a proxy server, which may or may not be important to your task.

    However it seems to me that you might not be writing software IPCONFIG will only give the IPv4 and v6 ethernet information for your computers network adapters. When behind a router and your TCP/IP settings are configured using DHCP, you are pretty much guaranteed that your IP address will be in a private network range (192.168.*, 10.0.*, etc.). From the perspective of your computer the IP on the WAN side of your router is inaccessible unless you jump through some hoops. I'm sure there's all kinds of tricky ways you could get the info you want, but simply doing an HTTPRequest to a service like ipchicken.com or whatismyip.com will give you what you want. At the same time, this is probably also the easiest way of finding your router's external IP for other reasons as well (besides programming). Sure, you could log into your router and use some fancy software but why bother when you can open your browser and hit ipchicken.com

    Zero

    ps. The reason that Vista closes the window for IPConfig right away is due to the manner in which you are starting the program (which is the Console [cmd.exe], not IPConfig). It is not a Vista issue. Instead of just typing ipconfig on Vista's search bar, try one of the following ways to get results from ipconfig:

    • cmd /k ipconfig {hit 'enter'}
    • cmd {hit 'enter'}
      • ipconfig {hit 'enter'}

    You could also go into Network Connections, double-click the icon for your network adapter, and go into Details which will give you all of the information for that specific NIC.

    Having said all this, it's probably worth pointing out that if your question is really about IPConfig and the differences between Vista vs. XP rather than programming then your post is wwwwaayyyyyy off-topic. Not to be a jerk or anything, but definately read before posting, search before posting and use your judgement to decide whether or not a group is appropriate for your question. Sorry if I'm off-base though.


  • chris99

    Would that work for a WinForm's application
  • Getting IP Addresses