Get list of Tor exit IP addresses using Ruby

Get list of Tor exit IP addresses using Ruby

Panggi Libersa J.A bio photo By Panggi Libersa J.A Comment

You know Tor, and i don’t have to explain it to you about this cool opensource project. In this post i’m going to show you how to get list of all near real time IP addresses of Tor exit nodes using Ruby.

Basically there are three simple steps in this implementation:

And here is the implementation in Ruby:

require 'net/http'
require 'uri'

tor_exits_url = ''
start_time =
raw_tor_exits = Net::HTTP.get(URI.parse(tor_exits_url))

if raw_tor_exits
  ips = raw_tor_exits.scan(/\b(?:(?: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]?)\b/)
  if ips
    filename = "tor-list-#{}.txt"
    write_to_file =, 'w') { |file| file.write(ips) }
    end_time =
    if write_to_file
      puts "Successfully written to #{filename} with #{ips.count} IP addresses in #{end_time - start_time} sec(s)"
      puts "Can't store IP addresses to #{filename}"
    puts "Can't extract IP addresses form raw data"
  puts "Can't get raw Tor IPs"

Run it:

$ ruby get_tor_list.rb
$ Successfully written to tor-list-1434561916.txt with 1180 IP addresses in 4.045044 sec(s)

The file contains an array of IP addresses:

$ cat tor-list-1434561916.txt
$ ["", "", "", "",...]

Now you can use these IP addresses for whatever you want like blocking the access of anyone with these IP addresses that visits your site.