Redirecting external IP to localhost

Discussion in 'Windows 7 Networking' started by BHeart, Apr 25, 2011.

  1. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    Hey folks.

    I would like to know how you can redirect an external IP to localhost. Im trying to emulate the server for a simple program one of my friends coded in C++ (or something). It is basicly a login and register system, upon registering the program sends a HTTP request to the server (it requests a PHP file) with username & password parameters, if the username is not taken the server replies "1", if it is taken it replies "0".
    I made a PHP file on my server with the same name, though it would only return "0".

    So here is the deal, the program connects to a server that i dont have access to, nor do i have access to the program's source code and i can't change what IP the program connects to, so i will have to somehow forward the IP it connects to to my server's IP.
     
  2. Trouble

    Trouble Noob Whisperer

    Joined:
    Nov 30, 2009
    Messages:
    13,845
    Likes Received:
    833
    BHeart:
    Hello and welcome to the forums.
    Assuming you're running a local web server that responds to HTTP requests on port 80 then, you should be able to adjust the hosts file to accomplish this. Something like, for example
    TheIpAddressOfTheLocalWebServer TheUrlThatTheAppIsCalling
    192.168.1.111 windows7forums.com
     
    #2 Trouble, Apr 25, 2011
    Last edited: Apr 25, 2011
  3. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    I tried that, it is used to redirect hostnames or domain names, e.g. google.com, and cant redirect IP addresses. My friend's program connects to an IP (obviously), i tried adding the hostname for the IP to my hosts file, but that didn't work either.

    And yes, i am running a standard web/HTTP server that responds to port 80.
     
  4. Trouble

    Trouble Noob Whisperer

    Joined:
    Nov 30, 2009
    Messages:
    13,845
    Likes Received:
    833
    Yep, that's correct redirects URLs to IP and won't work IP to IP.
    It's been a long time since I messed with the "Route" command, you can google it and try, probably something like
    Route Add IpAddressAppIsCalling mask 255.255.255.255 127.0.0.1
    route add 64.233.169.99 mask 255.255.255.255 127.0.0.1 (or instead of the local host loopback try the actual IP address that the HTTP server is responding on)
     
  5. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    I tried messing with the route command a little, i tried "route add 64.233.169.99 mask 255.255.255.255 127.0.0.1" (i edited the parameters of course), though i get an error: "Rutetilføjelse mislykkedes: Forkert parameter" (in danish), roughly translated to english: "Route addition failed: Wrong parameter"
     

    Attached Files:

    #5 BHeart, Apr 25, 2011
    Last edited: Apr 25, 2011
  6. Trouble

    Trouble Noob Whisperer

    Joined:
    Nov 30, 2009
    Messages:
    13,845
    Likes Received:
    833
    Try dropping the last .255 from the final octet and see if that works. (255.255.255.0)
    It may also be expecting an interface parameter in the case of multiple NICs and or a metric value in most case locally 1
    Keep us posted.
     
  7. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    I was messing around, typing random numbers into the metric thing. Sometimes it threw me a "Element not found" error, the rest of the times it threw me the "Wrong parameter". Could you show me an example or something? Im really confused about this metric thing..
     
  8. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    Progress! (I think)

    I added the IP to my route table (with this cmd: "route add <ip> <target>" ("<ip>" being my friend's IP and "<target>" my own IP, NOT 127.0.0.1)). But, now when i try to sign in using the program or request the file through my browser it fails to load it, even though my HTTP server is running and responds when i use localhost, internal or external IP.
     
  9. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    Nobody can help? :(
     
  10. BHeart

    BHeart New Member

    Joined:
    Apr 25, 2011
    Messages:
    14
    Likes Received:
    0
    Bump. I really need your help guys :/
     
  11. dvo

    dvo New Member

    Joined:
    Mar 5, 2012
    Messages:
    2
    Likes Received:
    0
    Just found out: Either add a loopback device and assign it the desired IP address, or
    maybe add a secondary ip address in the extended settings of your existing network device.
    Both can go with netmask 255.255.255.255.
    The first option worked better for me (after some silly device driver issues at first).

    See e.g.
    redirection - How do I redirect a request for an IP to the loopback? - Super User
    redirect an ip address to localhost - Page 2
     

Share This Page

Loading...