I wrote a small server using eventmachine.
the problem is that I want to use linux TPROXY for an outgoing connection.
using raw tcpsockets I can select the destination then set the socket
opts for tproxy and connect.
example code for TPROXY client:
##start
#!/usr/bin/env ruby
require 'socket'
Socket::IP_TRANSPARENT = 19 # since ruby dosnt have this constant
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
socksrcaddr = Socket.pack_sockaddr_in(3232, '127.0.0.7')
sockdstaddr = Socket.pack_sockaddr_in(3232, '127.0.0.1')
sock.setsockopt(Socket::SOL_IP, Socket::IP_TRANSPARENT, 1)
sock.bind(socksrcaddr)
sock.connect(sockdstaddr)
....
##end
a basic EM connect works with dst host + dst port + module\class
##start
EM::run do
bot = EM::connect $config_host, $config_port, Bot
bot.on_command_1 do |user, *args|
# handle command_1 in a block
end
# or if you want to modularize it, something like this
# where Command2Handler = lambda {|user, *args| #... }
bot.on_command_2(&Command2Handler)
end
##end
What I want to do is "EM::tproxy_connect $config_host, $config_port,
Bot, src_ip, src_port"
the src_ip and src_port should be nil by default and will be used in
either combination or just ip and the port will be randomized.
I have seen something about that there is a method to set the socket ops
and something about binding to specific ip and port but i'm kind of lost
it in the code.
Any help will be gladly welcomed
Thanks,
Eliezer
--
Eliezer Croitoru
https://www1.ngtech.co.il
IT consulting for Nonprofit organizations
eliezer <at>
ngtech.co.il