The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 01:50:37 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: Possible to change IP of PHP commands like fsockopen?  (Read 5915 times)
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« on: May 23, 2008, 10:50:43 AM »

Alright, so this is a bit of a newbie question, but one I've been wondering about for awhile.

So for example, in CURL it is possible to change the request IP through either CURLOPT_PROXY or CURLOPT_INTERFACE.

Is anything I can do that mimics that IP-changing effect when I use PHP functions like fsockopen or the PHP IMAP extension (given that I have extra IPs bound to the server)?
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: May 23, 2008, 10:54:43 AM »

If you search around in the php repository, I think there's an example of binding to a different IP on a box than the default gateway... I think that VSloathe demonstrated it or perhaps it was TheDarkness, not sure.
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.
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #2 on: May 23, 2008, 07:02:07 PM »

TD posted how to enumerate local IPs and return one, but that's not going to help us here.

Let me see what I can do...

You're going to need to use the socket API to bind to a different IP... something like this, but you will need to do error checking (catch exception, etc.)

Code:
<?php
$szSourceIP 
'yourOutBoundIP'//Local interface to which to bind
$szWebsite 'domain.com'//Site you want to grab from
$oSocket socket_create(AF_INETSOCK_STREAMSOL_TCP);
socket_bind($oSocket$szSourceIP);
socket_connect($oSocket$szWebsite80);
$szRequest 'GET / HTTP/1.1'."\r\n".'Host: '.$szWebsite."\r\n\r\n"//CRLFs tee hee
socket_write($oSocket$szRequest);
socket_close($oSocket);
?>


No idea if it works, written in this window.
Logged

hai
sysbuilder
Rookie
**
Offline Offline

Posts: 17


View Profile
« Reply #3 on: May 30, 2008, 11:10:23 PM »

Thanks vsloathe - that was exactly what I was looking for, appreciate it.
Logged

No links in signatures please
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #4 on: May 31, 2008, 06:38:35 AM »

Nothing at all wrong with VSs code but............

Code:
$opts = array(
    'socket' => array(
        'bindto' => '192.168.0.100:0',
    ),
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);
$context = stream_context_create($opts);
$fp = fopen('http://www.example.com', 'r', false, $context);

I'm currently into contexts, they rock!

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
Pages: [1]
  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!