0

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?

4

2 回答 2

0

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.

于 2010-04-03T22:56:42.630 回答
0

这可以在 Perl 中轻松完成。

查看perldoc perlipcIO::SocketIO::Select示例。

您可能会发现Beej 的网络编程指南也很有帮助。这些示例都是用 C 语言编写的,但 Perl 的网络 API 非常接近 C 风格。

于 2010-04-03T23:27:54.630 回答