Guest User

てすや

a guest
Sep 28th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.37 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # UNCOding: utf-8
  3. require 'uri'
  4. require 'yaml'
  5. begin
  6.   require 'socksify'
  7.   TCPSocket::socks_server = '127.0.0.1'
  8.   TCPSocket::socks_port = 9050
  9. rescue
  10.   require 'socket'
  11.   print 'Torを使わずに通信しますが宜しいですか[Y/n]? '
  12.   exit unless gets[0].to_upper === 'Y'
  13. end
  14.  
  15. if ARGV.size < 1
  16.   puts '使い方: ruby cross.rb form.yaml'
  17.   puts 'socksify-rubyを使ったりするのがいいです'
  18.   exit
  19. end
  20.  
  21. msg_list = []
  22. msg_yaml = File.read(ARGV[0]).encode!('Shift_JIS')
  23. msg_obj = YAML.load(msg_yaml)
  24. iter = proc do |key, value|
  25.   if value.is_a? Array
  26.     value.each_with_index do |value, i|
  27.       iter[key + '[' + i.to_s + ']', value]
  28.     end
  29.   else
  30.     pair = URI.encode_www_form_component(key)
  31.     pair << '='
  32.     pair << URI.encode_www_form_component(value)
  33.     msg_list << pair
  34.   end
  35. end
  36. msg_obj.each &iter
  37. message = msg_list.join('&')
  38.  
  39. socket = TCPSocket.open('cross-law.jp', 80)
  40. socket.puts <<__END_OF_REQUEST__
  41. POST /inquiry/ HTTP/1.1
  42. Host: cross-law.jp
  43. User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 5.0.2124.2070; Windows 6.0; MSIE 8.0.6001.18241)
  44. Referer: http://cross-law.jp/inquiry/
  45. Connection: keep-alive
  46. Content-Type: application/x-www-form-urlencoded
  47. Content-Length: #{message.size}
  48.  
  49. #{message}
  50. __END_OF_REQUEST__
  51. result = socket.read
  52. File.open('result.html', 'w') do |file| file << result end
Advertisement
Add Comment
Please, Sign In to add comment