Bill.Oakley Posted August 27, 2009 Share Posted August 27, 2009 I am looking for a way that can set which Network device my script will use. In essence I have a TCP peripheral device with its own Network Connection via USB (let's call it Local Area Connection 2), the peripheral device acts as a DHCP server giving an IP address assigned of 192.168.11.2 At the same time the device also responds to UDP connections on a separate address of 12.0.0.1. There are no issues creating a connection to the device for TCP communications, however when I attempt communications via UDP the connection attempt is invariably routed to my prime Local Area Connection device rather than the peripheral. Disabling the prime Local Area Connection will allow the UDP traffic onto Local Area Connection 2 - and the device will respond, but only as long as it is the only active connection. Ok - so we could assign an IP address to the device (same as the original DHCP assigned address), and add a second address in the 12.0.0.x range. This will bind the adaptor to the required range however it does not make the script fully transportable. Is there a way to control which network device my script will use? without having to force IP address ranges. Currently I am using a socket client class for the 192... address TCP traffic, and a simple fsockopen arrangement for the UDP traffic. Operating system is windows (XP). This has had me stumped for some time now and I would greatly appreciate some assistance. Quote Link to comment Share on other sites More sharing options...
Bill.Oakley Posted August 28, 2009 Author Share Posted August 28, 2009 Ok may have found a solution... I'll put it here in case someone else comes across the same issue one day and needs a guide. Windoze XP is capable as acting as a router, just that the route capability is by default switched off. To enable routing edit HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\TCPIP\Parameters. Look for IPEnableRouter and change from 0 [default] to 1. This can also be done by a PHP script by using the COM capability and the windoze inbuilt WSript.shell capability. Enabling my script to remain transportable and do the registry check / registry changes as required (keep in mind I am looking at distributing with something like XAMPP [bless them] and the script shouldn't require intervention of an IT tech to run) . Once routing is enabled, we can also run the windoze route command set such as: route ADD 12.0.0.0 MASK 255.0.0.0 192.168.11.2 to 'connect' the two IP ranges together. We can also specify the interface to be used for the routing! You can do more and I will be experimenting, refer the Windows ROUTE command - let alone WScript.shell which is real playground... Interesting aspect of my hunting around to find a solution is that there is a way to manipulate the windoze registry using PHP which I didn't think could be done. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.