tor_detector 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tor_detector/base.rb +46 -0
- data/lib/tor_detector/version.rb +3 -0
- data/lib/tor_detector.rb +3 -0
- data/tor_detector.gemspec +34 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccdac22f3528da72db18b823184e7fb2139e4338
|
4
|
+
data.tar.gz: 33d2af66f07046338ce2659414fcef46a1527fc8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3bf8e38d72d36569bb2887fd0d226a458bb95effafefd4a97cb6235c2dc919e172dbc7064d2ee1a689358ef82873e191fdfb0547f3401bb7db7ddc24685e047
|
7
|
+
data.tar.gz: 2038e97f36774ac4af871f85767f6107716d4c5f6ddb9faab250f839c46a315ce9ef276d1a0a30608dbb924cdf97421b8d964cf2cdaa8d9c3222dd06f12c6769
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# TorDetector
|
2
|
+
|
3
|
+
Detect if an IP is a TOR exit node.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'tor_detector'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install tor_detector
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
tor_detector = TorDetector.new
|
25
|
+
tor_detector.call('1.2.3.4') # => returns true or false
|
26
|
+
```
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pagedegeek/tor_detector.
|
37
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'tor_detector'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'ipaddr'
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
module TorDetector
|
5
|
+
MalformedIP = Class.new(StandardError)
|
6
|
+
|
7
|
+
# tor_detector = TorDetector::Base.new
|
8
|
+
# tor_detector.call('1.2.3.4')
|
9
|
+
class Base
|
10
|
+
attr_reader :dns_ip,
|
11
|
+
:dns_port
|
12
|
+
|
13
|
+
def initialize(dns_ip = '8.8.8.8', dns_port = 53)
|
14
|
+
@dns_ip = dns_ip
|
15
|
+
@dns_port = dns_port
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(ip)
|
19
|
+
IPAddr.new(ip)
|
20
|
+
Resolv.getaddress(tor_hostname_for(ip)) == positive_tor_ip
|
21
|
+
rescue IPAddr::InvalidAddressError
|
22
|
+
raise MalformedIP
|
23
|
+
rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH, Resolv::ResolvError
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def positive_tor_ip
|
30
|
+
'127.0.0.2'
|
31
|
+
end
|
32
|
+
|
33
|
+
def reverse_ip(ip)
|
34
|
+
ip.split('.').reverse.join('.')
|
35
|
+
end
|
36
|
+
|
37
|
+
def tor_hostname_for(ip)
|
38
|
+
[
|
39
|
+
reverse_ip(ip),
|
40
|
+
dns_port,
|
41
|
+
reverse_ip(dns_ip),
|
42
|
+
'ip-port.exitlist.torproject.org'
|
43
|
+
].join('.')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/tor_detector.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'tor_detector/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'tor_detector'
|
8
|
+
spec.version = TorDetector::VERSION
|
9
|
+
spec.authors = ['Sam']
|
10
|
+
spec.email = ['samuel@pagedegeek.com']
|
11
|
+
|
12
|
+
spec.summary = 'Detect if IP is exit node of TOR'
|
13
|
+
spec.description = 'Detect if IP belongs to TOR'
|
14
|
+
spec.homepage = 'https://github.com/pagedegeek/tor_detector'
|
15
|
+
|
16
|
+
if spec.respond_to?(:metadata)
|
17
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
|
+
else
|
19
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
20
|
+
'public gem pushes.'
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tor_detector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Detect if IP belongs to TOR
|
56
|
+
email:
|
57
|
+
- samuel@pagedegeek.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/tor_detector.rb
|
71
|
+
- lib/tor_detector/base.rb
|
72
|
+
- lib/tor_detector/version.rb
|
73
|
+
- tor_detector.gemspec
|
74
|
+
homepage: https://github.com/pagedegeek/tor_detector
|
75
|
+
licenses: []
|
76
|
+
metadata:
|
77
|
+
allowed_push_host: https://rubygems.org
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.8
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Detect if IP is exit node of TOR
|
98
|
+
test_files: []
|