Guest User

Untitled

a guest
Oct 27th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. require 'mysql2'
  2. ##########################################################################
  3. #
  4. # Script to insert new proxies into database from delimited .txt file
  5. #
  6. ##########################################################################
  7.  
  8. ######## First let's connect to that sexy ass MySQL database ##############
  9. $proxy_database = Mysql2::Client.new(:host => 'localhost', :username => 'carpanda', :password => 'alexcarpanda')
  10. $proxy_database.query("USE proxy_database")
  11.  
  12. #CREATE TABLE proxy_table (id INTEGER PRIMARY KEY NOT NULL, ip TEXT, port TEXT, alive_boolean BOOL);
  13. #inet_aton and inet_ntoa to convert ip to integer
  14. if $proxy_database
  15. puts "Successfully connected to proxy database"
  16. else
  17. puts "Bad connection to proxy databse, exiting..."
  18. return
  19. end
  20.  
  21. ####### Parse the input file into ip and port array-> proxyList #######
  22. proxyFileList = File.new('6_19_2011.txt', 'r')
  23. proxyList = []
  24. while (proxy = proxyFileList.gets)
  25. proxy = proxy.split(/:|\n|\r/)
  26. proxyList << { 'ip' => proxy[0], 'port' => proxy[1]}
  27. end
  28. proxyFileList.close
  29. puts "Converted the mutha effin txt file"
  30.  
  31. ######## Put the proxies from the text file into the DB if they are new #########
  32.  
  33. for i in 0...proxyList.length
  34. $proxy_database.query("INSERT proxy_table (id,ip,port,alive_boolean) VALUES (inet_aton('#{proxyList[i]['ip']}'),'#{proxyList[i]['ip']}','#{proxyList[i]['port']}','1') ON DUPLICATE KEY UPDATE alive_boolean=1")
  35. end
  36. puts "Entered new proxies into db!"
Add Comment
Please, Sign In to add comment