netscan_calife 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f19a1690cea13ba42dfce8c6c92d2eebaabd1dbc
4
- data.tar.gz: 6329be0195e66f73487860b32138b692a41d1f64
3
+ metadata.gz: 9ec978d6b7dede57678ddf5d72fc40cd83dfc58e
4
+ data.tar.gz: 188bf4bc4866a21aef09918d665319523d3a7fb6
5
5
  SHA512:
6
- metadata.gz: 3f4138fc88476019a4a80c2ad7a283fcbc1d382ba3a5b0ec134f20178281b79434808b91daf3ec997bf8bd8bd17004e59adb572ab42df2fe42d00990f75acda7
7
- data.tar.gz: d197b6925cee9219191af1fb2c0c1ed0198a78fa7e879552d192b90fb435c22f6daadc3f6644f31f59971fe38848cf37cee029d9a07d4dd4342ec728ab95ab5f
6
+ metadata.gz: 08c4edcf45c312e05ec3b7f587e93519c26ad16fa52d2228cbd6179ea46d76b23bda23206f7f3ff6e4fb157d69ba45630cb92dd459c7a76f75286e6c7277a979
7
+ data.tar.gz: 012cb3cfbcffe911881b5df9a87bbeebf0e604b1a7dfa1972073918d863e1596f7ea31157f0e14929a7edd56a9398fc5be3920e0eeea1d449cd6af9386eaa12f
data/bin/netscan_calife CHANGED
@@ -5,6 +5,9 @@ require 'optparse'
5
5
  require 'pp'
6
6
 
7
7
  options = {}
8
+ # Default value
9
+ # options[:filename]=ENV["HOME"]+"/scan.txt"
10
+
8
11
 
9
12
  parser=OptionParser.new do |opts|
10
13
  opts.banner = "Usage:#{ __FILE__} [options]"
@@ -21,6 +24,10 @@ parser=OptionParser.new do |opts|
21
24
  options[:netmask] = netmask
22
25
  end
23
26
 
27
+ opts.on('-fOUTFILE', '--filename OUTFILE', 'Filename') do |filename|
28
+ options[:filename] = filename
29
+ end
30
+
24
31
  opts.on('-h', '--help', 'Displays Help') do
25
32
  puts opts
26
33
  exit
@@ -60,5 +67,16 @@ unless NetscanCalife::Utils.valid_ipnetmask?(options[:netmask])
60
67
  end
61
68
  # End check
62
69
 
63
- # Main Run
64
- NetscanCalife::IpScan.format_result(NetscanCalife::IpScan.scan(options[:network].to_s,options[:netmask].to_s))
70
+
71
+ # Main
72
+ scan_result=NetscanCalife::IpScan.scan(options[:network].to_s,options[:netmask].to_s)
73
+
74
+ unless(options[:filename].nil?) # Write result to file
75
+ NetscanCalife::IpScan.to_yaml(scan_result,options[:filename])
76
+ else # Output result to console
77
+ NetscanCalife::IpScan.format_result(scan_result)
78
+ end
79
+
80
+ # puts "Loading result"
81
+ # loaded_result=NetscanCalife::IpScan.from_yaml()
82
+ # NetscanCalife::IpScan.format_result(loaded_result)
@@ -1,6 +1,8 @@
1
- require 'benchmark'
2
1
  require 'ipaddr'
3
- require 'pp'
2
+ require 'yaml'
3
+
4
+ #require 'benchmark'
5
+ #require 'pp'
4
6
 
5
7
  module NetscanCalife
6
8
 
@@ -37,12 +39,44 @@ module NetscanCalife
37
39
 
38
40
  end
39
41
 
42
+
43
+ #
44
+ # === Serialize scan result to yaml file
45
+ # * *Args* :
46
+ # - ++ -> data
47
+ #
48
+ def self.to_yaml(data,filename)
49
+
50
+ File.open(filename,"w") { |fileobj|
51
+ YAML.dump(data,fileobj)
52
+ }
53
+
54
+ end
55
+
56
+
57
+ #
58
+ # === Read data from yaml file
59
+ # * *Args* :
60
+ # - ++ -> filename
61
+ # * *Returns* :
62
+ # -
63
+ # TODO: handle exceptions
64
+ #
65
+ def self.from_yaml(filename)
66
+
67
+ File.open(filename) { |fileobj|
68
+ YAML.load(fileobj)
69
+ }
70
+
71
+ end
72
+
40
73
  =begin
41
- Print scan result
74
+ Print scan result
42
75
  =end
43
76
  def self.format_result(data,fmt='txt')
44
77
 
45
78
  case fmt
79
+
46
80
  when 'txt'
47
81
  printf "%s\n","-----------------------------------------"
48
82
  printf "|\t%s\t\t|\t%s\t|\n","HOST","FOUND"
@@ -50,7 +84,31 @@ Print scan result
50
84
  data.each { |host,found|
51
85
  printf "|\t%s\t|\t%s\t|\n","#{host}","#{found}"
52
86
  }
53
- printf "%s\n","-----------------------------------------"
87
+ printf "%s\n","-----------------------------------------"
88
+
89
+ when 'html'
90
+ printf "%s\n","<table>"
91
+ printf "%s\n","<tr>"
92
+ printf "%s\n","<th>"
93
+ printf "%s\n","HOST"
94
+ printf "%s\n","</th>"
95
+ printf "%s\n","<th>"
96
+ printf "%s\n","FOUND"
97
+ printf "%s\n","</th>"
98
+ printf "%s\n","</tr>"
99
+ data.each { |host,found|
100
+ printf "%s\n","<tr>"
101
+ printf "%s\n","<td>"
102
+ printf "%s\n","#{host}"
103
+ printf "%s\n","</td>"
104
+ printf "%s\n","<td>"
105
+ printf "%s\n","#{found}"
106
+ printf "%s\n","</td>"
107
+ printf "%s\n","</tr>"
108
+ }
109
+ printf "%s\n","</table>"
110
+ else
111
+ stderr "Format not supported"
54
112
  end
55
113
 
56
114
  end
@@ -1,3 +1,3 @@
1
1
  module NetscanCalife
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netscan_calife
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - calife
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-10 00:00:00.000000000 Z
11
+ date: 2015-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler