![]() |
thedarkness
<? phpfunction _getip() { exec("ifconfig", $ips); $ regex= "@addr (? ?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))@";$ipstr = implode( $ips ); $ipstr = preg_replace( "@127.0.0.1@", "", $ipstr ); // Don't want localhost preg_match_all( $ regex, $ipstr, $matches );return $matches[1][array_rand( $matches[1] )]; } // Example usage print _getip(); ?> AS usual, if anyone can suggest a better way, let us all know about it. Cheers, td perkiset
Nice one TD... that'll come in handy actually.
thedarkness
quote author=perkiset link=topic=243.msg1525#msg1525 date=1179461814 Nice one TD... that'll come in handy actually. Already has perk, already has ![]() Cheers, td thedarkness
Take my advice and put the full path to ifconfig in the call to exec e.g. "/sbin/ifconfig"
I just burned hours on this, it was buried so deep and for some reason it was working intermittently ![]() ??There be weirdness, td thedarkness
Usage: (this one's
PHP5.x only) because of the use of the stream context;<? phpfunction _getfile($url) { ini_set('error_reporting', E_ALL); $false = 0; exec("/sbin/ifconfig", $ips); $ regex= "@addr (? ?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))@";$ipstr = implode( $ips ); $ipstr = preg_replace( "@127.0.0.1@", "", $ipstr ); // Don't want localhost preg_match_all( $ regex, $ipstr, $matches );$opts = array( 'socket' => array( 'bindto' => $matches[1][array_rand( $matches[1] )].':0' ) ); $context = stream_context_create($opts); results = file_get_contents( $url, $false, $context ); return results; } ?> This one's PHP4.x+;<? phpfunction _getfile($url) { exec("/sbin/ifconfig", $ips); $ regex= "@addr (? ?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))@";$ipstr = implode( $ips ); $ipstr = preg_replace( "@127.0.0.1@", "", $ipstr ); // Don't want localhost preg_match_all( $ regex, $ipstr, $matches );$URI_PARTS = parse_url( $url ); $sock = socket_create( AF_ INET, SOCK_STREAM, SOL_TCP );socket_bind ( $sock, $matches[1][array_rand( $matches[1] )] ); $ip = gethostbyname( $URI_PARTS['host'] ); socket_connect ( $sock, $ip, 80 ); $request = 'GET '.$URI_PARTS['path'].'?'.$URI_PARTS['query']." HTTP/1.1 ". 'Host: '.$URI_PARTS['host']." "; socket_write( $sock, $request ); $results = ''; while( $buffer = @socket_read( $sock, 512 , PHP_NORMAL_READ ) )$results .= $buffer; socket_close( $sock ); return $results; } ?> perkiset
The more I read this and think about some of my boxes, the more I like it
thedarkness
We're here to help
![]() Cheers, td |
Thread Categories
| Best of The Cache Home | ||
| Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads



(?
