networkwatcherd 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 320d10346786a0c94a6ca0e10306921028e0c618
4
+ data.tar.gz: 0aee89e9daa379efe7bde9a21b7b28bf14910c82
5
+ SHA512:
6
+ metadata.gz: 3aedc7b6c388c0c9c3a9333b2438032cb3aac4a05eac9a5a2dce3395e5d2a91b673e67bc1ff72d54c91ed46e9bde1cf3e54c5c596c76223be9ce9805aee28b58
7
+ data.tar.gz: d918437c907b97c1c281145ba4fd7534d72d3fa0c7c5f57d7c02cd6c69e2b8c9550da2c5abb9945156d9b9f73b9ae314237b0759df6f166f286c851d0941ce9c
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Signal.trap('INT') { abort }
4
+
5
+ require 'optparse'
6
+ require 'networkwatcherd'
7
+ require 'networkwatcherd/version'
8
+ #Start the real shit
9
+
10
+
11
+ options = {:timeout => nil, :sleep => nil, :ippattern => nil,:devices => nil}
12
+
13
+ parser = OptionParser.new do|opts|
14
+ opts.banner = "Usage: networkwatcherd [options]"
15
+
16
+ opts.on('-t', '--timeout timeout', 'Notification timeout (Default 50 second)') do |timeout|
17
+ options[:timeout] = timeout;
18
+ end
19
+ opts.on('-d', '--number-of-devices devices', 'Number of addresses to ping (Default 254 )') do |devices|
20
+ options[:devices] = devices
21
+ end
22
+ opts.on('-s', '--sleep sleep', 'Time between each devices checking (Default 300 second)') do |sleep|
23
+ options[:sleep] = sleep;
24
+ end
25
+
26
+ opts.on('-p', '--ip-pattern ippattern',' (Default 192.168.1)') do |ippattern|
27
+ options[:ippattern] = ippattern;
28
+ end
29
+ opts.on('-v','--version','Current version') do
30
+ puts Networkwatcherd::VERSION
31
+ exit
32
+ end
33
+ opts.on('-h', '--help', 'Displays Help') do
34
+ puts opts
35
+ exit
36
+ end
37
+ end
38
+ parser.parse!
39
+
40
+ options[:timeout] ||= 50.5
41
+ options[:sleep] ||= 300
42
+ options[:ippattern] ||= "192.168.1"
43
+ options[:devices] ||= 254
44
+ S = Scanner.new(options[:devices].to_i)
45
+ while true
46
+ S.scan options[:ippattern],options[:sleep],options[:timeout]
47
+ end
48
+
@@ -0,0 +1,22 @@
1
+ require 'networkwatcherd/networkdevices'
2
+
3
+ module IPScanner
4
+ def self.network_devices(nd,ip_pattern)
5
+ (0..nd).each do |n|
6
+ ip = "#{ip_pattern}.#{n}"
7
+ output = `ping -c1 #{ip}`
8
+ data = output.split
9
+ #p data[12]
10
+ if data[12] != "Unreachable"
11
+ device_raw_ip = data[1]
12
+ if device_raw_ip != nil
13
+ device = NetworkDevices.new(device_raw_ip)
14
+ yield device
15
+ end
16
+ end
17
+ #p n
18
+ end
19
+
20
+ end
21
+ end
22
+
@@ -0,0 +1,17 @@
1
+ class NetworkDevices
2
+ attr_reader :ip_dn
3
+ def initialize (ip)
4
+ @ip = ip
5
+ @ip_dn = @ip.split(".").at(3).to_i
6
+ end
7
+ def inspect
8
+ @ip
9
+ end
10
+ def value
11
+ @ip_dn
12
+ end
13
+ def <=> (other)
14
+ @ip_dn <=> other.ip_dn
15
+ end
16
+ end
17
+
@@ -0,0 +1,22 @@
1
+ require 'libnotify'
2
+
3
+ module Notification
4
+ def self.send (summary,new_fags,timeout=50.5)
5
+ #text = new_fags.join(" and ")
6
+ text = ""
7
+ #new_fags.shift
8
+ new_fags.each do |d|
9
+ text+="#{d.inspect} "
10
+ end
11
+ notification = Libnotify.new do |notify|
12
+ notify.summary = "Network Watcher"
13
+ notify.body = text
14
+ notify.timeout = timeout
15
+ notify.urgency = :critical
16
+ notify.append = false
17
+ notify.transient = true
18
+ end
19
+ notification.show!
20
+
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ require 'networkwatcherd/ipscanner'
2
+ require 'networkwatcherd/notification'
3
+
4
+ class Scanner
5
+ @@default_nd_value = 254
6
+ def initialize (nd=@@default_nd_value)
7
+ @nd = nd
8
+ @ip_old_list = Array.new(@nd)
9
+ @ip_new_list = Array.new(@nd)
10
+ @ip_new_list.fill("")
11
+ @ip_old_list.fill("")
12
+ end
13
+
14
+ def scan(ip_pattern="192.168.1",time=300,timeout=50.5)
15
+ #@ip_old_list ||= Array.new(@nd)
16
+ @ip_old_list = @ip_new_list.map(&:clone)
17
+ @ip_new_list = Array.new(@nd)
18
+ @ip_new_list.fill("")
19
+ IPScanner.network_devices(@nd,ip_pattern) { |d|
20
+ @ip_new_list[d.value] = d
21
+ } #Get the new fags.
22
+ new_fags = []
23
+ (0..@nd).each do |n|
24
+ if @ip_new_list[n] != "" and @ip_old_list[n] == ""
25
+ new_fags.push(@ip_new_list[n])
26
+ end
27
+ end
28
+ #p new_fags if !new_fags.empty?
29
+ Notification.send("New Devices",new_fags) if !new_fags.empty?
30
+ end
31
+ end
32
+
@@ -0,0 +1,3 @@
1
+ module Networkwatcherd
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'networkwatcherd/notification'
2
+ require 'networkwatcherd/networkdevices'
3
+ require 'networkwatcherd/ipscanner'
4
+ require 'networkwatcherd/scanner'
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: networkwatcherd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Khaled
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libnotify
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.1
33
+ description: Sends you a notification when another device connect to your network
34
+ email: nemoload@aol.com
35
+ executables:
36
+ - networkwatcherd
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - bin/networkwatcherd
41
+ - lib/networkwatcherd.rb
42
+ - lib/networkwatcherd/ipscanner.rb
43
+ - lib/networkwatcherd/networkdevices.rb
44
+ - lib/networkwatcherd/notification.rb
45
+ - lib/networkwatcherd/scanner.rb
46
+ - lib/networkwatcherd/version.rb
47
+ homepage: http://github.org/nemoload/networkwatcherd
48
+ licenses:
49
+ - Apache-2.0
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubyforge_project:
67
+ rubygems_version: 2.5.1
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Network devices watcher
71
+ test_files: []