From: John Yuan on 29 Mar 2010 23:26
I may shooting a wrong question, but I saw the same question here that
left unanswered and gone 60 days more, so I want to raise it once again.
I have 3 NIFs :
1. PPP1 (188.8.131.52)：PPTP to VPN
2. eth2 (192.168.0.2) ：LAN
3. ppp3 (333.333.333.333)：PPPoE to ASDL
and want to bind a specific interface to Mechanize agent somehow like :
like the way Socket does. But I haven't have any luck yet.
Did anyone try yet or shouldn't expect Mechanize package working in this
any suggestion would be appreciated !!
Posted via http://www.ruby-forum.com/.
From: Walton Hoops on 30 Mar 2010 09:45
On 3/29/2010 9:26 PM, John Yuan wrote:
> I may shooting a wrong question, but I saw the same question here that
> left unanswered and gone 60 days more, so I want to raise it once again.
> I have 3 NIFs :
> 1. PPP1 (184.108.40.206)：PPTP to VPN
> 2. eth2 (192.168.0.2) ：LAN
> 3. ppp3 (333.333.333.333)：PPPoE to ASDL
> and want to bind a specific interface to Mechanize agent somehow like :
> agent.bind(Socket.sockaddr_in(80, "220.127.116.11"))
> agent.bind(Socket.sockaddr_in(80, "192.168.0.2"))
> agent.bind(Socket.sockaddr_in(80, "333.333.333.333"))
> like the way Socket does. But I haven't have any luck yet.
> Did anyone try yet or shouldn't expect Mechanize package working in this
> any suggestion would be appreciated !!
It doesn't work that way. Mechanize is a client, not a server. The NIC
used is decided by the destination IP and the routes in your Operating
System. Only server sockets can be bound to one or more IPs.
From: John Yuan on 31 Mar 2010 00:58
Walton Hoops wrote:
> It doesn't work that way. Mechanize is a client, not a server. The NIC
> used is decided by the destination IP and the routes in your Operating
> System. Only server sockets can be bound to one or more IPs.
Thank you Walton,
I am afraid that your comment would be the most the answer after
spending quite sometime searching for solution. You helped me to put the
period to my approach.
It may not be Ruby specific problem, but let me explain the situation.
My client has 3 accounts on B2B site and all 3 accounts need to accessed
with specific IP address (3 different offices, 3 different IPs). I was
asked to write script to show consolidated inventory list over those 3
So I sat up a Debian with 3 NICs, VPN/LAN/PPP to 3 different offices
network and “proxying” 3 different IPs to gather 3 account inventory
level and consolidate them “simultaneously”. Right now to change
interface, I manually change routing to NIFs when switching account, but
the process is slow and it's accessing account one by one, even though
the connections are simultaneously available, causing slight difference
of the inventory level by the time 3rd account was checked out.
My goal is to launch 3 threads of Mechanize agents to access the same
URI (inventory.b2b.com/login) through 3 different NIFs (ppp1/eth2/ppp3)
From: John W Higgins on 31 Mar 2010 01:42
[Note: parts of this message were removed to make it a legal post.]
On Tue, Mar 30, 2010 at 9:58 PM, John Yuan <johnyuan2000(a)gmail.com> wrote:
> My goal is to launch 3 threads of Mechanize agents to access the same
> URI (inventory.b2b.com/login) through 3 different NIFs (ppp1/eth2/ppp3)
Your best bet might be to set up 3 proxies and have each of the Mechanize
clients hit a different proxy (using set_proxy for each instance) which
would push each request to the proxy's assigned server.
Something nice and simple like this should work (
- you would need 3 changes to this file
1) Obviously line 3 needs to have a different port for each of the proxies
2) Line 4 would need to point to a different ip corresponding to each of the
three instances of inventory.b2b.com and the port would be 80 obviously
3) You don't want any substitution here so line 12 would simply be resp
In theory that should push the requests to the appropriate server for you
without a huge amount of work. I think you'll find em-proxy extremely
flexible in terms of getting this task done for you. As with anything that
messes with network traffic - there is some overhead - but you seem much
more concerned with concurrency than milliseconds of delay.
From: Alexey Bovanenko on 1 Apr 2010 01:38
Hi. You cannot bind the client socket. You must bind only server
socket which recieves client connections. In your case you can use
proxy solution for specific sites or you can write paths for selected
sites in gateway table on your computer.
On 4/1/10, John W Higgins <wishdev(a)gmail.com> wrote:
> If you wish to run the example as is you need to run all three lines
> ruby examples/appserver.rb 81 - this runs a webserver which is referenced in
> line 4 of the line_interceptor example as the final destination. Think of it
> as a tiny tiny version of the webserver you are trying to connect to.
> ruby examples/line_interceptor.rb - this fires up the proxy - the error you
> are getting is that it is trying to connect to the server started just above
> which you are I'm guessing not running
> curl localhost - this uses curl to make a request that hits the proxy that
> then sends the request off to the appserver.rb to get the response -
> modifies the result and returns it to you.
> You will need rack installed to have appserver.rb work.
> Hope this helps move you along......
Sent from my mobile device