-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathpspider.rb
executable file
·96 lines (82 loc) · 2.02 KB
/
pspider.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env ruby
# require gems and needed files
require_relative 'lib/environment'
Environment.require_all
# initialize helper
libhelper = LibHelper.new
# output banner
libhelper.banner
# no user input
if ARGV.empty?
libhelper.help
puts
libhelper.usage
puts
exit
end
# default vars
domain = nil
pages = nil
all = nil
all_pages = nil
all_files = nil
neighbours = nil
url_keywords = nil
keywords = nil
# user input
opts = GetoptLong.new(
[ '--domain', '-d', GetoptLong::REQUIRED_ARGUMENT ],
[ '--pages', '-p', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--all', '-a', GetoptLong::NO_ARGUMENT ],
[ '--allpages', GetoptLong::NO_ARGUMENT ],
[ '--allfiles', GetoptLong::NO_ARGUMENT ],
[ '--neighbours', GetoptLong::NO_ARGUMENT ],
[ '--urlkeywords', GetoptLong::NO_ARGUMENT ],
[ '--keywords', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ]
)
# parse user input
opts.each do |opt, arg|
case opt
when '--domain'
domain = arg
when '--pages'
pages = arg.to_i
when '--all'
all = true
when '--allpages'
all_pages = true
when '--allfiles'
all_files = true
when '--neighbours'
neighbours = true
when '--urlkeywords'
url_keywords = true
when '--keywords'
keywords = true
when '--help'
libhelper.help
end
end
if ! PublicSuffix.valid?( domain )
puts "[ERROR] The domain supplied (#{domain}) is not a valid domain!"
exit
end
if ! libhelper.domain_exists?( domain )
puts "[ERROR] The domain supplied (#{domain}) does not exist!"
exit
end
# make all default if no other options selected
all = true if ! all && ! all_pages && ! all_files && ! neighbours && ! url_keywords && ! keywords
# initialize objects
bing = Bing.new( domain, pages )
# start bing api calls
bing.get_all if all
bing.get_all_pages if all_pages
bing.get_all_files if all_files
bing.get_ip_neighbours if neighbours
bing.get_url_keywords if url_keywords
bing.get_keywords if keywords
# output output mofo
ModuleHelper.output.stdout
exit