header_handler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/header_handler.rb +133 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca3ee483631fef213b22723a724fb420f9bdff45
|
4
|
+
data.tar.gz: 0242d6ff28294d90c2ceec1110df562f69fb7167
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fdd02eab8cc794fa4ebe34f24036a4f8ff5981086608d39f94896e95188b95dfade3e26e7c54d5c77cbd5d254ca0221bbd9bea6a1f707689f175d43670e49f69
|
7
|
+
data.tar.gz: e35789dc6d6f92273f326bfc58b2914919500ab7a5fce270a7ca4c583e20b178a180fd86d81f20f76512cb7208c765908d7dfc2b8fc2687947ca37ab76bcdd6a
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# header_handler.rb
|
2
|
+
#
|
3
|
+
# Copyright (C) June 26, 2014
|
4
|
+
#
|
5
|
+
# Author: Abbas Taghiloei AKA MR.0x41 <ox41_a@yahoo.com>
|
6
|
+
#
|
7
|
+
# == License
|
8
|
+
#
|
9
|
+
# The MIT License (MIT)
|
10
|
+
#
|
11
|
+
# Copyright (c) [2014] [header_handler v 0.0.1 Ruby Gem]
|
12
|
+
#
|
13
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
+
# of this software and associated documentation files (the "Software"), to deal
|
15
|
+
# in the Software without restriction, including without limitation the rights
|
16
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
+
# copies of the Software, and to permit persons to whom the Software is
|
18
|
+
# furnished to do so, subject to the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be included in all
|
21
|
+
# copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
24
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
25
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
26
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
27
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
28
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
29
|
+
# SOFTWARE.
|
30
|
+
#
|
31
|
+
# == OverView
|
32
|
+
#
|
33
|
+
# This Gem created to handle you headers while sending request to webservers
|
34
|
+
# And see the webserver result, I mean the response headers. Not the html Body.
|
35
|
+
#
|
36
|
+
# == Usage
|
37
|
+
#
|
38
|
+
# Create :
|
39
|
+
# test = HeaderHandler.new('www.testcom', '/index2.php', 80, {'User-Agent' => "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)",
|
40
|
+
# 'Accept' => "text/html"})
|
41
|
+
# ok = test.isok? ## This will check the server if socket can be create and it checks the response header status, it will return 1 if 200 and 2 for else
|
42
|
+
# ## and 0 if socket can not create.
|
43
|
+
#
|
44
|
+
# res = Hash.new
|
45
|
+
# res = test.send_get
|
46
|
+
#
|
47
|
+
# Method will return a Hash containing the server response to your header, you can access to the header filds in this way :
|
48
|
+
# res["Date"]
|
49
|
+
|
50
|
+
|
51
|
+
require 'socket'
|
52
|
+
|
53
|
+
class HeaderHandler
|
54
|
+
def initialize(addr, path='/', port=80, head={})
|
55
|
+
@addr, @path, @port = addr, path, port
|
56
|
+
@headers = Hash.new
|
57
|
+
@headers = {'User-Agent' => "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36",
|
58
|
+
'Accept' => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
59
|
+
'Accept-Language' => "en-US",
|
60
|
+
'Accept-Encoding' => "gzip,deflate",
|
61
|
+
}
|
62
|
+
@headers = @headers.merge(head).to_a
|
63
|
+
@i = 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def send
|
67
|
+
begin
|
68
|
+
con = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
|
69
|
+
con.connect Socket.pack_sockaddr_in(@port, @addr)
|
70
|
+
con.puts "GET #{@path} HTTP/1.1"+"\r\n"
|
71
|
+
con.puts "Host: #{@addr}"+"\r\n"
|
72
|
+
while(@i < @headers.size)
|
73
|
+
con.puts "#{@headers[@i][0]}: #{@headers[@i][1]}"+"\r\n"
|
74
|
+
@i += 1
|
75
|
+
end
|
76
|
+
con.close
|
77
|
+
rescue SocketError
|
78
|
+
return 0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
def isok?
|
82
|
+
begin
|
83
|
+
header_response = ''
|
84
|
+
con = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
|
85
|
+
con.connect Socket.pack_sockaddr_in(@port, @addr)
|
86
|
+
con.puts "GET #{@path} HTTP/1.1"+"\r\n"
|
87
|
+
con.puts "Host: #{@addr}"+"\r\n"
|
88
|
+
while(@i < @headers.size)
|
89
|
+
con.puts "#{@headers[@i][0]}: #{@headers[@i][1]}"+"\r\n"
|
90
|
+
@i += 1
|
91
|
+
end
|
92
|
+
con.puts "Connection: keep-alive"+"\n\n"
|
93
|
+
header_response = con.gets
|
94
|
+
con.close
|
95
|
+
if(header_response =~ /20/)
|
96
|
+
return 1
|
97
|
+
else
|
98
|
+
return 2
|
99
|
+
end
|
100
|
+
rescue SocketError
|
101
|
+
return 0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
def send_get
|
105
|
+
begin
|
106
|
+
con = Socket.new Socket::AF_INET, Socket::SOCK_STREAM
|
107
|
+
con.connect Socket.pack_sockaddr_in(@port, @addr)
|
108
|
+
con.puts "GET #{@path} HTTP/1.1"+"\r\n"
|
109
|
+
con.puts "Host: #{@addr}"+"\r\n"
|
110
|
+
while(@i < @headers.size)
|
111
|
+
con.puts "#{@headers[@i][0]}: #{@headers[@i][1]}"+"\r\n"
|
112
|
+
@i += 1
|
113
|
+
end
|
114
|
+
res = ''
|
115
|
+
header_response = Hash.new
|
116
|
+
con.puts "Connection: keep-alive"+"\n\n"
|
117
|
+
while res = con.gets
|
118
|
+
if(res =~ /</ || res =~ /\\/)
|
119
|
+
break
|
120
|
+
else
|
121
|
+
if(res =~ /:/)
|
122
|
+
a, b = res.split (/: /)
|
123
|
+
header_response[a] = b
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
con.close
|
128
|
+
return header_response
|
129
|
+
rescue SocketError
|
130
|
+
return 0
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: header_handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- A-Taghiloei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Simple Gem to handle HTTP Headers you sent and the server responses.
|
14
|
+
Uses Socket Lib for connecting more faster.
|
15
|
+
email: ox41_a@yahoo.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/header_handler.rb
|
21
|
+
homepage: http://www.opensec.ir
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.0
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.0
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: A Simple Gem to handle HTTP Headers.
|
45
|
+
test_files: []
|