Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 69 lines (57 sloc) 1.935 kB
cbb1912 @chriso Added initial built-in modules
authored
1 usage = '''
0cb932c @chriso Updated built-in module usage details
authored
2 This module provides DNS resolution utilities
cbb1912 @chriso Added initial built-in modules
authored
3
4 1. To resolve domains and return "domain,ip":
5 $ node.io resolve < domains.txt
6
7 2. To return domains that do not resolve (potentially available):
8 $ node.io resolve available < domains.txt
9
10 3. To return domains that do resolve:
11 $ node.io resolve found < domains.txt
12
13 3. To return unique IPs:
14 $ node.io resolve ips < domains.txt
15 '''
16
17 nodeio = require 'node.io'
18 dns = require 'dns'
804ebb5 @chriso Less aggressive with resolve retries
authored
19 options = {max: 100, timeout: 5, retries: 1}
cbb1912 @chriso Added initial built-in modules
authored
20
21 # Outputs "domain,ip"
22 class ResolveAll extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
23 run: (domain) ->
cbb1912 @chriso Added initial built-in modules
authored
24 dns.lookup domain, 4, (err, ip) =>
25 if err? then @retry() else @emit domain + ',' + ip
26 fail: (domain) -> @emit domain + ',failed'
27
28 # Outputs domains that have a record
29 class HasRecord extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
30 run: (domain) ->
cbb1912 @chriso Added initial built-in modules
authored
31 dns.lookup domain, 4, (err, ip) =>
32 if err? then @retry() else @emit domain
33 fail: (domain) -> @skip()
34
35 # Outputs domains that do not have a record
36 class Available extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
37 run: (domain) ->
cbb1912 @chriso Added initial built-in modules
authored
38 dns.lookup domain, 4, (err, ip) =>
39 if err? then @retry() else @skip()
40 fail: (domain) -> @emit domain
41
42 # Outputs unique IPs
43 unique_ips = []
44 class UniqueIPs extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
45 run: (domain) ->
cbb1912 @chriso Added initial built-in modules
authored
46 dns.lookup domain, 4, (err, ip) =>
47 if err? then @retry() else
d5779e6 @chriso Whitespace removal rampage
authored
48 if ip in unique_ips
49 @skip()
cbb1912 @chriso Added initial built-in modules
authored
50 else
51 unique_ips.push ip
52 @emit ip
53 fail: (domain) -> @skip()
54
55 class UsageDetails extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
56 input: ->
cbb1912 @chriso Added initial built-in modules
authored
57 @status usage
58 @exit()
59
60 #Run `node.io resolve [all|found|available|ips] < input.txt`
61 @class = ResolveAll
62 @job = {
63 all: new ResolveAll(options)
64 found: new HasRecord(options)
65 available: new Available(options)
66 ips: new UniqueIPs(options)
67 help: new UsageDetails()
d5779e6 @chriso Whitespace removal rampage
authored
68 }
Something went wrong with that request. Please try again.