Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # UNCOding: utf-8
- require 'uri'
- require 'yaml'
- begin
- require 'socksify'
- TCPSocket::socks_server = '127.0.0.1'
- TCPSocket::socks_port = 9050
- rescue
- require 'socket'
- print 'Torを使わずに通信しますが宜しいですか[Y/n]? '
- exit unless gets[0].to_upper === 'Y'
- end
- if ARGV.size < 1
- puts '使い方: ruby cross.rb form.yaml'
- puts 'socksify-rubyを使ったりするのがいいです'
- exit
- end
- msg_list = []
- msg_yaml = File.read(ARGV[0]).encode!('Shift_JIS')
- msg_obj = YAML.load(msg_yaml)
- iter = proc do |key, value|
- if value.is_a? Array
- value.each_with_index do |value, i|
- iter[key + '[' + i.to_s + ']', value]
- end
- else
- pair = URI.encode_www_form_component(key)
- pair << '='
- pair << URI.encode_www_form_component(value)
- msg_list << pair
- end
- end
- msg_obj.each &iter
- message = msg_list.join('&')
- socket = TCPSocket.open('cross-law.jp', 80)
- socket.puts <<__END_OF_REQUEST__
- POST /inquiry/ HTTP/1.1
- Host: cross-law.jp
- User-Agent: Mozilla/4.0 (compatible; GoogleToolbar 5.0.2124.2070; Windows 6.0; MSIE 8.0.6001.18241)
- Referer: http://cross-law.jp/inquiry/
- Connection: keep-alive
- Content-Type: application/x-www-form-urlencoded
- Content-Length: #{message.size}
- #{message}
- __END_OF_REQUEST__
- result = socket.read
- File.open('result.html', 'w') do |file| file << result end
Advertisement
Add Comment
Please, Sign In to add comment