Results 1 to 13 of 13
  1. #1
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default Redirect IP to 127.0.0.1?

    How would I go about redirecting an ip to localhost?

    Example:

    If I have a client that always connects to a certain ip,

    Is there anyway to make that client connect to 127.0.0.1 instead? (In Java)

    Then on 127.0.0.1, I would have a server running to accept the connection.
    Last edited by Bill89; 12-06-2009 at 04:59 PM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    That's interesting. In theory I can imagine it might be possible to do a kind of the socket connections by proxying them to the localhost witha java based application, but only if it was on that machine with that client ip address.

    For the general case, such as to have an application on your machine that wants to connect to some remote machine, a simple way to have it connect to your localhost, would be to create an entry for that remote machine in your hosts file, but this doesn't work for IP addresses.

    I guess in theory, if you were able to add a second alias IP address to your machine, of the value of the remote one you would want to have redirected to your machine, the operating system routing table should see that address as a local route.

    But in the general case to have traffic from your machine or for every maching in your office, the best way to do this would be to use an operating system network level facility, such as iptables in linux, or pf in freebsd, where you can have filter rules to mangle or redirect network packets based on the source or target IP addresses. Where this kind of thing would be set up on the gateway device between your machine and the target machine you want to have redirected, such as through NAT or bridged configuration

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Any solution would need, of course, to be installed on that client. since 127.0.0.1 is localhost, it can only be connected to from the local machine, so any "solution" would have to come from that machine itself. Redirecting network traffic that has already reached a switch won't help. Natting, iptables and the like can help if set up for outgoing coms and is running on the local machine, of course.

    May I ask what exactly, the problem is? Or, said differently, what, exactly, you are trying to acheive by "redirecting" the connection?

  4. #4
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Don't think I explained it well.

    I have a java client(on my pc) that connects to a java server(That I don't have access to) on another network.

    Instead of having the java client connect to the ip it normally does, I want to force it to connect to 127.0.0.1(Which is just another java server).

    If the java client connected to a host name instead of an ip, then I could I use the windows host file, and that would do exactly what I want.

    Both the java client, and my java server will be running on the same pc.
    Last edited by Bill89; 12-07-2009 at 11:35 AM.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Does it have any configuration files? Do you have access to the code? "your server" could also open a port on the public interface, and then you can use external routing/natting/ip tables to route it back to "your server". The real question is why do you want it to connect locally to "your server". What, exactly is the problem? Does the program not start if you cannot access that server? In which case writing your own probably won't help as it probably does some sort of actual exchange to determine that it has connected to the "right" server (even if only through SSL/certificate/whatever or just a specific protocol). Are you maybe trying to circumvent a license restriction (i.e. demo to permanent)? Are you maybe trying to snoop out the protocol (if so there is an easier and better way)?

  6. #6
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    The real question is why do you want it to connect locally to "your server".
    My server that would be running on localhost, would just be a proxy server that would send whatever packets it receives(from the java client) to the official server.

    And also whenever the official server sent a packet to it's client, it would go through my proxy server first.

    Then on the proxy server, I would be able to filter out/change packets from both the official server, and the java client. Or even send packets to them both, from the proxy server.

    But I can't do this, until I have the java client connect to localhost instead of the official server.

    Quote Originally Posted by masijade View Post
    Does it have any configuration files? Do you have access to the code?
    The java client doesn't have any config files that would be able to change the ip it connects to.

    And I don't have access to the src.
    Last edited by Bill89; 12-07-2009 at 11:55 AM.

  7. #7
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Bill89 View Post
    My server that would be running on localhost, would just be a proxy server that would send whatever packets it receives(from the java client) to the official server.

    And also whenever the official server sent a packet to it's client, it would go through my proxy server first.
    You claimed you don't have access to the network, so how? If there is some other proxy server on your local network (not local machine) then why not "redirect" directly to that? (Edit: Nevermind on this point, you said you don't have access to the server.)

    Then on the proxy server, I would be able to filter out/change packets from both the official server, and the java client. Or even send packets to them both, from the proxy server.

    But I can't do this, until I have the java client connect to localhost instead of the official server.
    So you are trying hack/snoop the thing? If not, why do you feel the need to falsify/spoof the info?

    The java client doesn't have any config files that would be able to change the ip it connects to.

    And I don't have access to the src.
    Last edited by masijade; 12-07-2009 at 12:18 PM.

  8. #8
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    You claimed you don't have access to the network, so how?
    I don't have access to network that runs the official server.

    Quote Originally Posted by masijade View Post
    If there is some other proxy server on your local network (not local machine) then why not "redirect" directly to that?
    That's what I'm trying to do. Except that the proxy server, is on the "local machine".

    Quote Originally Posted by Bill89 View Post
    that connects to a java server(That I don't have access to) on another network.
    ^ Was referring to the official server.
    Last edited by Bill89; 12-07-2009 at 12:31 PM.

  9. #9
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    So, you still haven't said why you feel the need to do it. Although It sure looks, as I've said, like a hack attempt. If so, I'll just leave it at that.

  10. #10
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    So, you still haven't said why you feel the need to do it. Although It sure looks, as I've said, like a hack attempt. If so, I'll just leave it at that.
    Automation of the client.

  11. #11
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Write your own network classes and place them in the bootstrap classpath before rt.jar. Not guaranteed to work though, and you would probably have to write your own version of all classes in that/those packages.

  12. #12
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    You could simply screw with the hosts file in system32/drivers/etc ;)
    I die a little on the inside...
    Every time I get shot.

  13. #13
    Bill89 is offline Member
    Join Date
    Dec 2009
    Location
    Maine
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by Supamagier View Post
    You could simply screw with the hosts file in system32/drivers/etc ;)
    If you could redirect an ip to localhost, then yes.

Similar Threads

  1. Redirect To Same Page
    By systech44 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-08-2009, 12:27 PM
  2. How to redirect the output
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-04-2008, 03:36 PM
  3. How to redirect the output
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 10:30 PM
  4. how to redirect the browser
    By simon in forum Java Applets
    Replies: 1
    Last Post: 08-02-2007, 06:24 PM
  5. How can I redirect in servlet?
    By Heather in forum Java Servlet
    Replies: 1
    Last Post: 07-14-2007, 06:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •