Programming: Forced Redirection
  • I've got an application that is supposed to connect to the server on a specific IP and port (I know that data) but I want to redirect it so it would connect to an application I launched on my computer. I think there is a host file (I'm using Windows) that contains IPs to be redirected automatically but that's not exactly what I want. I want the redirection at the specific time. Let's say I start my server (on my computer) and it listened to that application. As it has connected or the server went down, I don't want the redirection anymore.

    Any hints/functions/anything how to code that?
  • Well I suppose the difficulty depends on the language, even though it shouldn't be too difficult in any language.

    I suppose that if you just code something to find the current time, and then if it's in a certain range use a different IP address and port number.
  • Sorry, my bad. I forgot to mention that the project is on C++. And the application isn't coded by me so I haven't got the code/compilation. I'm working on that other application that is going to listen. So I have to tell Windows (or whatever else is needed) that application must connect to you instead of the default IP (or that anything that connects to IP xxx on port xxx must connect to you)
  • The only way that I know to go about this is to modify the Hosts file, but Windows requires a restart to respect changes to the Hosts file (AFAIK).

    So, you'll (probably) have to write something that will add a line to the Hosts file, and then restart windows based on the time. This might actually be kind of easy to do with a really simple C++ app and a Windows Scheduled Task.
  • No... Restart isn't what I want. That's why I want to make a program that would force the redirection automatically - I don't want to edit/restart my computer each time. Just run and it works...
  • you don't have to restart with Windows. What you are asking I am not sure that it can be done "easily". Have you application connect on the correct port. Check you registry / config files for the ip you are trying to redirect. It would be dumb to hard code an ip address.
    Hello World!
  • EDIT: I was going to recommend rinetd, but it doesn't do what you want. Sorry 'bout that.
  • Does it use IPs or domain names? You could run a local BIND server and then you can tell it to redirect domain names to specific IPs on the fly.
  • It's connecting to the IP, not the domain. But, as I said before, I want to code a program that forces that application to redirect. It's not created to be done so, that's why I want to force it.
  • Maybe look into this http://www.hsc.fr/ressources/outils/pktfilter/
    It runs at the driver level so it may be able to route the IP before it leaves your computer.
  • The problem is that I want to code it, not to use any software or something. I want to code a function that would do so. The program I want to make is supposed to do way more than just redirect - it's just a piece of it.
  • I'm fairly certain that the only way you'll be able to do this is to write your own drivers; perhaps creating a virtual network interface. If you were to create a virtual interface, you could set it so all traffic is routed through it and use some sort of rules-based filtering to determine which packets you want to redirect. This would be a non-trivial undertaking, but you should be able to find some open source/public domain code to help you out.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Poll

No poll attached to this discussion.

In this Discussion