开发者

Monitor socket with ngrep or perl for activity, then issue command

开发者 https://www.devze.com 2022-12-25 07:58 出处:网络
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 dat

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 开发者_StackOverflowanother ipaddress, such as "192.168.1.102"

Is this even possible?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消