Created
September 18, 2014 16:44
-
-
Save joelbrewer/af249a59822e0aeb92b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env ruby | |
| require 'pg' | |
| require 'resolv' | |
| # This script is used to query score.senderscore.com for senderscores | |
| # Given an array of IPs the script will query for their sender scores | |
| # and save the info to a database | |
| # | |
| # Author: Joel Brewer ([email protected]) | |
| class SenderScore | |
| @@ips = ["216.153.28.51", "216.153.28.52", "216.153.28.53"] | |
| def run | |
| @@ips.each do |ip| | |
| save_sender_score(ip, get_sender_score(ip)) | |
| end | |
| end | |
| def reverse_ip(ip) | |
| ip.split(".").reverse.join(".") | |
| end | |
| def get_sender_score(ip) | |
| reverse_ip = reverse_ip(ip) | |
| sender_ip = reverse_ip + ".score.senderscore.com" | |
| address = Resolv.new.getaddress(sender_ip) | |
| sender_score = address.split(".")[3] | |
| end | |
| def save_sender_score(ip, score) | |
| conn = connect_to_database | |
| time = Time.now.to_i | |
| res = conn.exec_params('INSERT INTO sender_score (ip, score, time) VALUES ($1, $2, $3)', [ip, score, time]) | |
| end | |
| def connect_to_database | |
| PGconn.connect( :hostaddr => "127.0.0.1", :dbname => "avant_dashboard", :user => "joelbrewer", :password => "XXXX" ) | |
| end | |
| ss = SenderScore.new | |
| ss.run | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment