uutdns 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/uutdns +60 -0
- data/lib/uutdns.rb +102 -0
- data/lib/uutdns/version.rb +3 -0
- data/uutdns.gemspec +23 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Aref Aslani
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Uutdns
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'uutdns'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install uutdns
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/uutdns
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require 'uutdns'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
$type = :standard
|
7
|
+
$ip
|
8
|
+
$domain
|
9
|
+
$server = "127.0.0.1"
|
10
|
+
$port = 53
|
11
|
+
|
12
|
+
# Parse command line optoions
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "A simple DNS client built in Ruby written by Aref Aslani"
|
15
|
+
opts.separator "options:"
|
16
|
+
|
17
|
+
opts.on("--ip IP",
|
18
|
+
"Gets the IP address as argument and returns domain name") do |ip|
|
19
|
+
$type = :inverse
|
20
|
+
$ip = ip
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("--domain DOMAIN",
|
24
|
+
"Gets the DOMAIN as argument and returens the IP address") do |domain|
|
25
|
+
$type = :standard
|
26
|
+
$domain = domain
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("--server SERVER",
|
30
|
+
"Gets DNS server ip address(default value is 127.0.0.1)") do |server|
|
31
|
+
$server = server
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on("--port PORT",
|
35
|
+
"Gets DNS server port number(default value is 53)") do |port|
|
36
|
+
$port = port
|
37
|
+
end
|
38
|
+
end.parse!
|
39
|
+
|
40
|
+
dns = UUTDNS.new
|
41
|
+
dns_msg = ''
|
42
|
+
|
43
|
+
case $type
|
44
|
+
when :standard
|
45
|
+
dns_msg = dns.header($type) + dns.question($domain)
|
46
|
+
when :inverse
|
47
|
+
puts "Inverse lookup not implemented yet."
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
ds = UDPSocket.new(:INET)
|
52
|
+
ds.connect($server, $port)
|
53
|
+
ds.send(dns_msg, 0)
|
54
|
+
response, address = ds.recvfrom(1024)
|
55
|
+
|
56
|
+
puts "The DNS header for the domain \"#{$domain}\" is: " + dns.header($type)
|
57
|
+
puts "The DNS question part for the domain \"#{$domain}\" is: " + dns.question($domain)
|
58
|
+
|
59
|
+
puts "The server response is:"
|
60
|
+
p response
|
data/lib/uutdns.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
require "uutdns/version"
|
2
|
+
|
3
|
+
class UUTDNS
|
4
|
+
def bin_to_hex(s)
|
5
|
+
hex_value = ""
|
6
|
+
s.scan(/(........)/).each do |x|
|
7
|
+
value = x[0].to_i(2).to_s(16)
|
8
|
+
value.prepend("0") if value.length == 1
|
9
|
+
hex_value << value
|
10
|
+
end
|
11
|
+
hex_value.upcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def header(type = :standard)
|
15
|
+
header = ''
|
16
|
+
|
17
|
+
# Set id
|
18
|
+
16.times do
|
19
|
+
header << [*0..1].sample.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
# Set the QR to 0 as this is a query, not a response
|
23
|
+
header << "0"
|
24
|
+
|
25
|
+
# Set the header Opcode
|
26
|
+
# 0 for standard query
|
27
|
+
# 1 for inverse query
|
28
|
+
case type
|
29
|
+
when :standard
|
30
|
+
header << "0000"
|
31
|
+
when :inverse
|
32
|
+
header.opcode = "0001"
|
33
|
+
end
|
34
|
+
|
35
|
+
# Set AA to 0
|
36
|
+
# specifies that the responding name server is not an
|
37
|
+
# authority for the domain name in question section.
|
38
|
+
header << "0"
|
39
|
+
|
40
|
+
# TrunCation - specifies that this message was truncated
|
41
|
+
# due to length greater than that permitted on the
|
42
|
+
# transmission channel(just for response).
|
43
|
+
header << "0"
|
44
|
+
|
45
|
+
# Recursion Desired
|
46
|
+
header << "1"
|
47
|
+
|
48
|
+
# Recursion Available(just for response)
|
49
|
+
header << "0"
|
50
|
+
|
51
|
+
# Z - Reserved for future use.
|
52
|
+
header << "000"
|
53
|
+
|
54
|
+
# RCODE - just for responses. 0 indicate that there is no error
|
55
|
+
header << "0000"
|
56
|
+
|
57
|
+
# QDCOUNT - the number of entries in the question section.
|
58
|
+
header << "0" * 15 + "1"
|
59
|
+
|
60
|
+
# ANCOUNT - the number of resource records in the answer section(for answer.
|
61
|
+
header << "0" * 16
|
62
|
+
|
63
|
+
# NSCOUNT - an unsigned 16 bit integer specifying the number of name
|
64
|
+
# server resource records in the authority records section.
|
65
|
+
header << "0" * 16
|
66
|
+
|
67
|
+
# ARCOUNT - an unsigned 16 bit integer specifying the number of
|
68
|
+
# resource records in the additional records section.
|
69
|
+
header << "0" * 16
|
70
|
+
|
71
|
+
bin_to_hex(header)
|
72
|
+
end
|
73
|
+
|
74
|
+
def question(domain_name)
|
75
|
+
question = ''
|
76
|
+
question_parts = domain_name.split('.')
|
77
|
+
|
78
|
+
# Set QNAME
|
79
|
+
question_parts.each do |part|
|
80
|
+
part.length
|
81
|
+
part_bits = part.length.to_s(2)
|
82
|
+
# partlen_hex.prepend("0") if partlen_hex.length == 1
|
83
|
+
part_bits.prepend("0") while part_bits.length < 8
|
84
|
+
# p part_bits
|
85
|
+
question << part_bits
|
86
|
+
|
87
|
+
part.each_byte do |b|
|
88
|
+
byte_hex = b.to_s(2)
|
89
|
+
byte_hex.prepend("0") while byte_hex.length < 8
|
90
|
+
question << byte_hex
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
question = bin_to_hex(question) << "00"
|
95
|
+
|
96
|
+
# Set QTYPE
|
97
|
+
question << "0001"
|
98
|
+
|
99
|
+
# Set QCLASS
|
100
|
+
question << "0001"
|
101
|
+
end
|
102
|
+
end
|
data/uutdns.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uutdns/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "uutdns"
|
8
|
+
spec.version = Uutdns::VERSION
|
9
|
+
spec.authors = ["Aref Aslani"]
|
10
|
+
spec.email = ["arefaslani@gmail.com"]
|
11
|
+
spec.description = %q{Simple DNS Client built for Internet Engineering course in Urmia University of Technology}
|
12
|
+
spec.summary = %q{Simple DNS Client}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uutdns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aref Aslani
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Simple DNS Client built for Internet Engineering course in Urmia University
|
47
|
+
of Technology
|
48
|
+
email:
|
49
|
+
- arefaslani@gmail.com
|
50
|
+
executables:
|
51
|
+
- uutdns
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/uutdns
|
61
|
+
- lib/uutdns.rb
|
62
|
+
- lib/uutdns/version.rb
|
63
|
+
- uutdns.gemspec
|
64
|
+
homepage: ''
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Simple DNS Client
|
89
|
+
test_files: []
|