Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrico Sola authored and Enrico Sola committed Feb 11, 2018
0 parents commit 53f8aef
Show file tree
Hide file tree
Showing 9 changed files with 2,631 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

674 changes: 674 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Tor detector

A very simple library to detect Tor connections using PHP 7 without any dependency.

# Usage

Before using the library, you have to set the path to the file that contains the list of all Tor exit points, if you don't have the list you can set an arbitrary file name instead.
To set the library path, use this method:

`PHPTorDetector\PHPTorDetector::setListPath('nodes.txt');`

If the file doesn't exist or is empty or you just want to update its content, you can use this method to download the updated list and overwrite new list in the file:

`PHPTorDetector\PHPTorDetector::updateFile();`

Once you have the list, you can check if an IP address is part of the Tor network by using this method:

`$result = PHPTorDetector\PHPTorDetector::isTor('IP ADDRESS HERE');`

If you want to get the IP address of the client you can use this method:

`$address = PHPTorDetector\PHPTorDetector::getClientIPAddress();`

Are you looking for the Node.js version? Give a look [here](https://github.com/RyanJ93/tor-detector).
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "ryanj93/php-tor-detector",
"version": "1.1.0",
"description": "A very simple library to detect Tor connections using PHP 7 without any dependency.",
"type": "library",
"license": "GPL-3.0-or-later",
"homepage": "https://github.com/RyanJ93/php-tor-detector#readme",
"authors": [{
"name": "Enrico Sola",
"email": "sola.enrico.93@gmail.com",
"homepage": "https://www.enricosola.com"
}],
"require": {
"php": ">=7.0"
},
"keywords": [
"tor",
"proxy",
"validator",
"utilities",
"security"
],
"autoload": {
"files": [
"php-tor-detector.php"
]
}
}
14 changes: 14 additions & 0 deletions demo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
require dirname(__FILE__) . '/php-tor-detector.php';

$address = '89.234.157.254';

//Set the list path.
PHPTorDetector\PHPTorDetector::setListPath('nodes.txt');

//Update the content fo the list (or create the list if the file doesn't exist or is empty).
PHPTorDetector\PHPTorDetector::updateFile();

//Check if this IP address is a Tor exit point.
$result = PHPTorDetector\PHPTorDetector::isTor($address);
echo 'Is this client (' . $address . ') part of the Tor network? ' . ( $result === true ? 'Yes' : 'No' ) . '.' . PHP_EOL;
Loading

0 comments on commit 53f8aef

Please sign in to comment.