Posted by Ishkur on Sun 29 Jun 19:15
report abuse | download | new post
- <?php
- /**
- * PHP5 class for interfacing with the Tor network
- * by Josh Sandlin <josh@thenullbyte.org>
- *
- * Licensed: MIT/X11
- *
- * NOTE: The proxy host is configurable by the user,
- * so therefore one i not limited to only the Tor
- * network. The default setting however is to run
- * all data through the Tor/Privoxy network.
- *
- */
- class Tor
- {
- private $url;
- private $userAgent;
- private $timeout;
- private $proxy;
- private $vector;
- private $payload;
- private $returnData;
- public function Tor()
- {
- $this->url = null;
- $this->userAgent = null;
- $this->timeout = 300;
- $this->proxy = '127.0.0.1:9050';
- $this->vector = null;
- $this->payload = null;
- $this->returnData = null;
- }
- private function setUrl($url)
- {
- $this->url = $url;
- }
- private function setUserAgent()
- {
- //list of browsers
- 'Firefox',
- 'Safari',
- 'Opera',
- 'Flock',
- 'Internet Explorer',
- 'Seamonkey',
- 'Konqueror',
- 'GoogleBot'
- );
- //list of operating systems
- 'Windows 3.1',
- 'Windows 95',
- 'Windows 98',
- 'Windows 2000',
- 'Windows NT',
- 'Windows XP',
- 'Windows Vista',
- 'Redhat Linux',
- 'Ubuntu',
- 'Fedora',
- 'AmigaOS',
- 'OS 10.5'
- );
- //randomly generate UserAgent
- }
- private function setTimeout($timeout)
- {
- $this->timeout = $timeout;
- }
- public function setProxy($ip, $port)
- {
- $this->proxy = $ip .":". $port;
- }
- private function setVector($vector)
- {
- $this->vector = $vector;
- }
- private function setCurl()
- {
- $action = curl_init();
- curl_setopt($action, CURLOPT_PROXY, $this->proxy);
- curl_setopt($action, CURLOPT_URL, $this->payload);
- curl_setopt($action, CURLOPT_HEADER, 1);
- curl_setopt($action, CURLOPT_USERAGENT, $this->userAgent);
- curl_setopt($action, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($action, CURLOPT_FOLLOLOCATION, 1);
- curl_setopt($action, CURLOPT_TIMEOUT, $this->timeout);
- $this->returnData = curl_exec($action);
- curl_close($action);
- }
- private function setPayload()
- {
- $this->payload = $this->url . $this->vector;
- }
- public function launch($url, $vector, $timeout = null)
- {
- //set parameters
- $this->setUrl($url);
- $this->setVector($vector);
- $this->setUserAgent();
- //set payload
- $this->setPayload();
- //if a timeout is set in the args, use it
- {
- $this->setTimeout($timeout);
- }
- //run cURL action against url
- $this->setCurl();
- }
- public function getTorData()
- {
- 'url' => $this->url,
- 'userAgent' => $this->userAgent,
- 'timeout' => $this->timeout,
- 'proxy' => $this->proxy,
- 'payload' => $this->payload,
- 'return' => $this->returnData
- );
- }
- }
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.