Re: sockets and network interfaces
- From: "Jon Jensen" <jenseng@xxxxxxxxx>
- Date: 23 Sep 2005 01:17:18 -0700
I suppose it would have helped if I had looked at the socket functions
in greater depth before posting. I had already changed the default
source IP for the server (using "ip route chg...") when I discovered
this:
Example 1. Using socket_bind() to set the source address
<?php
// Create a new socket
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// An example list of IP addresses owned by the computer
$sourceips['kevin'] = '127.0.0.1';
$sourceips['madcoder'] = '127.0.0.2';
// Bind the source address
socket_bind($sock, $sourceips['madcoder']);
// Connect to destination address
socket_connect($sock, '127.0.0.1', 80);
// Write
$request = 'GET / HTTP/1.1' . "\r\n" .
'Host: example.com' . "\r\n\r\n";
socket_write($sock, $request);
// Close
socket_close($sock);
?>
http://us2.php.net/manual/en/function.socket-bind.php
Of course, socket_bind cannot be used in conjunction with fsockopen,
but the other socket functions can, which is exactly what I needed.
.
- References:
- sockets and network interfaces
- From: Jon Jensen
- sockets and network interfaces
- Prev by Date: Re: form and arrays[]
- Next by Date: Re: identify user lan
- Previous by thread: sockets and network interfaces
- Next by thread: PHP MYSQL Script
- Index(es):