terco 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING +19 -0
  3. data/LICENSE +19 -0
  4. data/README.md +48 -0
  5. data/bin/terco +59 -0
  6. data/terco.gemspec +14 -0
  7. metadata +50 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 555fb2c603820a3d8a9bf22295c6f4b37c2402e9
4
+ data.tar.gz: 06b0c20813327728ad7491d1a638b53cecfb048a
5
+ SHA512:
6
+ metadata.gz: db21333bea70e47fa3159d061c8a0b4d40e20bf6e3343bd61d9e35a24c07ccbe1e0f08faf29b0afdfc4ba0f7f2a1fc2847b7ab4d7648fe20e85eb4b5dca5c15e
7
+ data.tar.gz: 8984f36619642bd6f7c6fd492848172dd401700bb7eb66b582c65e9215f402fb1c3fe0aeb8d9b1c9c4ef7a6c5d9111a4f9b114687361d042d9f0316d2976d07c
@@ -0,0 +1,19 @@
1
+ This code tries to solve a particular problem with a very simple
2
+ implementation. We try to keep the code to a minimum while making
3
+ it as clear as possible. The design is very likely finished, and
4
+ if some feature is missing it is possible that it was left out on
5
+ purpose. That said, new usage patterns may arise, and when that
6
+ happens we are ready to adapt if necessary.
7
+
8
+ A good first step for contributing is to meet us on IRC and discuss
9
+ ideas. We spend a lot of time on #lesscode at freenode, always ready
10
+ to talk about code and simplicity. If connecting to IRC is not an
11
+ option, you can create an issue explaining the proposed change and
12
+ a use case. We pay a lot of attention to use cases, because our
13
+ goal is to keep the code base simple. Usually the result of a
14
+ conversation is the creation of a different tool.
15
+
16
+ Please don't start the conversation with a pull request. The code
17
+ should come at last, and even though it may help to convey an idea,
18
+ more often than not it draws the attention to a particular
19
+ implementation.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 Michel Martens
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ terco
2
+ =====
3
+
4
+ Obstinate DNS
5
+
6
+ Description
7
+ -----------
8
+
9
+ Terco is a DNS server that always resolves to 127.0.0.1.
10
+
11
+ It binds to port 53 by default, so probably you will have to sudo
12
+ it. If you want to run it in a different port, pass the port number
13
+ as the first argument.
14
+
15
+ One possible use is to configure your computer to resolve all requests
16
+ for a given TLD to your own computer.
17
+
18
+ Usage
19
+ -----
20
+
21
+ ``` console
22
+ $ terco
23
+ Listening on port 53
24
+ ```
25
+
26
+ Or, if you want to run it in the background:
27
+
28
+ ```console
29
+ $ terco &
30
+ ```
31
+
32
+ Now you can tell your OS to use `127.0.0.1:53` as your DNS for a
33
+ given TLD. Here's how to do it in OS X:
34
+
35
+ ```console
36
+ $ sudo mkdir /etc/resolver
37
+ $ sudo sh -c 'echo "nameserver 127.0.0.1" > /etc/resolver/dev'
38
+ ```
39
+
40
+ Now all domains that use the `.dev` TLD will point to `127.0.0.1`.
41
+
42
+ ## Installation
43
+
44
+ You can install it using rubygems.
45
+
46
+ ```
47
+ $ gem install terco
48
+ ```
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2015 Michel Martens
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'socket'
24
+
25
+ class Terco
26
+ HOST = "127.0.0.1".freeze
27
+ TMPL = "%s\x81\x80%s%s\x00\x00\x00\x00%s"\
28
+ "\xc0\x0c\x00\x01\x00\x01\x00\x00"\
29
+ "\x00\x3c\x00\x04\x7f\x00\x00\x01".b.freeze
30
+
31
+ def initialize(port = 53)
32
+ @sock = UDPSocket.new
33
+ @sock.bind(HOST, port)
34
+ end
35
+
36
+ def run
37
+ loop do
38
+ data, addr = @sock.recvfrom(1000)
39
+
40
+ packet = sprintf(TMPL, data[0,2], data[4,2], data[4,2], data[12..-1])
41
+
42
+ @sock.send(packet, 0, addr[3], addr[1])
43
+ end
44
+ end
45
+ end
46
+
47
+ port = ARGV.fetch(0, 53)
48
+
49
+ begin
50
+ server = Terco.new(port)
51
+ puts "Listening on port #{port}"
52
+ rescue Errno::EACCES
53
+ puts "Couldn't bind to port #{port}."
54
+ exit 1
55
+ end
56
+
57
+ Signal.trap("INT") { exit 0 }
58
+
59
+ server.run
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "terco"
5
+ s.version = "0.0.1"
6
+ s.summary = "Obstinate DNS"
7
+ s.description = "Terco is a DNS server that always resolves to 127.0.0.1"
8
+ s.authors = ["Michel Martens"]
9
+ s.email = ["michel@soveran.com"]
10
+ s.homepage = "https://github.com/soveran/terco"
11
+ s.files = `git ls-files`.split("\n")
12
+ s.license = "MIT"
13
+ s.executables.push("terco")
14
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michel Martens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Terco is a DNS server that always resolves to 127.0.0.1
14
+ email:
15
+ - michel@soveran.com
16
+ executables:
17
+ - terco
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CONTRIBUTING
22
+ - LICENSE
23
+ - README.md
24
+ - bin/terco
25
+ - terco.gemspec
26
+ homepage: https://github.com/soveran/terco
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.14
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Obstinate DNS
50
+ test_files: []