views:

114

answers:

2

I'd like to use ngrep and/or perl to monitor the incoming data stream on a socket, then, when the appropriate characters arrive, like in this case, the string "192.168.1.101:8080", input to the data stream a redirect to another ipaddress, such as "192.168.1.102"

Is this even possible?

A: 

Sure, thats possible.

Algorithm/application would require:

  • MiM listenning server (creating sockets session sockets)
  • hand-shake on MiM:
  • (best thing would be if there would be a text stream not binary protocol used)
  • recv from client, parse message then:

  • if IP comes in, open or use already opened socket to the target server/port

  • send message or rest of the message to target server
  • provide communication beteween client and target sever (operate as gateway)
  • recv() client or server and send() back to appropriate side

General advice: operate on select() or epoll(), approach more advanced but better.

bua
A: 

This can done easily in Perl.

Take a look at perldoc perlipc, IO::Socket and IO::Select for examples.

You might find Beej's Guide to Network Programming helpful, too. The examples are all in C, but Perl's networking API is pretty close to the C flavor.

daotoad