The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 18, 2019, 11:28:27 AM

Login with username, password and session length


Pages: [1] 2
  Print  
Author Topic: specifying NIC a script should use, running multiple instances using separate  (Read 8075 times)
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« on: July 14, 2010, 08:43:32 AM »

OK got some little scripts that are chugging away..

however I am able to get a wired connection and also a Wi Fi connection that are on totally separate internet connections..

what I would really like to be able to do is to launch these little PHP CLI scripts, but tell one instance to use the wired and one to use the WiFi

is that possible (surely)

I thought about maybe getting a proxy server running on the machine and setting that proxy to use a specific NIC, then I could just specify proxy settings in Curl and jobs done, though haven't actually been able to find out how I might go about doing that.

Any ideas?

help much appreciated as always Wink
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: July 14, 2010, 09:27:16 AM »

The problem will be if you only have a single NIC in the processing machine. It will have a single default gateway, regardless how many addresses it has on it. You could potentially use the ROUTE command and 2 different addresses on the box but that'd be a little hairy, and beyond my ability to assist.

The most effective way would be to have two NICs, each with their own address and gateway, then bind your PHP processes to one or the other. That'd do for the single process dual path idea.

Another way, however, would be to download ESXi, have two virtual machines running instead of just one, then each of them could have their own address and gateway on the same single NIC. This is also quite superior and needs no hardware upgrade, but entails a little more tech work.

Good luck! 
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #2 on: July 14, 2010, 09:29:06 AM »

Oh, and a third way, although a little different, would be to us pfSense as your final gateway machine, then set up multi WAN and use both chunks of bandwidth together for both processes - although you'd not have things separate, youd have the benefit of all the bandwidth for both processes - arguable the same result or actually better.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #3 on: July 15, 2010, 03:35:00 AM »

cheers for the replies Smiley

I think in fact you might have missed my point tho

I have a laptop doing some scraping etc

it has a wired network for my main internet connection, however it also has a wifi card which I can hook into another open wifi connection, thereby giving me two totally separate IP addresses to use

If I fire up my PHP script, it will always use the wired connection if its available, so the wifi is just doing nothing.

All I want to do, as easily as poss, is to force a single PHP script to use teh wifi even if the wired is plugged in

this is on Ubuntu btw

does that make sense?

thanks again for the help

edit:
i think actually you do understand - but its this bit I need help with:

"then bind your PHP processes to one or the other"
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: July 15, 2010, 08:52:28 AM »

I've not done it personally, but I think the easiest way I've seen it done is with cURL_set opt() there's one to select the interface that requests go out on. If you are not using curl I don't have an immediate answer. Hopefully someone else will jump in here, but I'll dig about and see what I remember in a bit.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #5 on: July 15, 2010, 09:02:21 AM »

On reflection though, you will have to have two separate processes running or multithread your code. If you multithread its going to be more difficult. So if you have 2 running, then create a little vmware virtual, have eth0 be shut down on it to force it to use the wifi and you're good to go. Kludgy but pretty quickly effective.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #6 on: July 15, 2010, 09:02:58 AM »

oh man that's actually so simple, thanks

CURLOPT_INTERFACE      The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.

got to love PHP + Curl  Grin

will be two separate processes so no worries there
Logged
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #7 on: July 15, 2010, 04:34:09 PM »

You can have multiple IP address on 1 nic.
If there is not a option in the program like in curl then not easy to fix.
In a nutshell when the socket is opened it binds to the default network device.
But you can tell it what IP address to bind to using socket operations (you would have to poke in the source).
As per this API http://www.opengroup.org/onlinepubs/009695399/functions/bind.html
Or make some sort of hook.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #8 on: July 15, 2010, 10:13:49 PM »

that's what got me at first as well. The challenge is 1 address each on 2 nics. Multi-wan essentially.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #9 on: July 16, 2010, 02:46:22 AM »

cheers guys

re this curl interface though, can't for the life of me get it to work

looks like I can't get it to work using straight up curl either

curl --interface wlan0 http://www.google.com

I have tried using wlan0, using the IP address nothing seems to work.

It does seem to be hooking up to it, but then the process times out with:
curl: (7) couldn't connect to host

heres my ifconfig for the wlan in question:

wlan0     Link encap:Ethernet  HWaddr 00:22:5f:11:f0:19 
          inet addr:192.168.2.5  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::222:5fff:fe11:f019/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1492  Metric:1
          RX packets:6327 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2892 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:641551 (641.5 KB)  TX bytes:565257 (565.2 KB)

Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #10 on: July 16, 2010, 06:25:31 AM »

If those are your actual ips, that's why it no worky. Those are private non routable ips. Your behind a firewall and ip is on a nice on that.
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #11 on: July 16, 2010, 09:04:39 AM »

hmm so your saying I need the actual external IP address (eg visit whatismyip using the wifi) and try setting that as the interface IP?
Logged
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #12 on: July 16, 2010, 09:16:45 AM »

this was bs actually - best just remove it..
« Last Edit: July 16, 2010, 09:46:45 AM by herbacious » Logged
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #13 on: July 16, 2010, 04:02:17 PM »

As NB said it is a routing issue.
http://php.net/manual/en/function.curl-setopt.php
You should be setting CURLOPT_INTERFACE to the IP addy of your interface.

But the catch is you can set the option to any IP addy, the packets will just not be able to route Smiley
You have to modify the routing tables. I am guessing that interface does not have a proper Gateway. I am not 100% sure how to do this.
It is not a simple task. Also make sure if you start monkeying with them, you make proper backups of the old entries. You can bugger your machine so it will not connect to the net. If you are using a remote host you will be fucked Smiley
Logged
herbacious
Journeyman
***
Offline Offline

Posts: 51


View Profile
« Reply #14 on: August 04, 2010, 02:13:22 PM »

cheers

yeah I abandonded this in the end..

easier to just set up curl slaves elsewhere and use them
Logged
Pages: [1] 2
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!