Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: c085682cda
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (65 sloc) 1.972 kB
require 'open-uri'
module Router
class << self
attr_accessor :hostname, :path
def url
"http://#{hostname}/#{path}"
end
def poll
NetworkStatus.new url
end
end
@hostname = '192.168.1.1'
@path = 'indexHiddenVZ.htm'
class NetworkStatus
attr_reader :state, :ip, :username, :devices
def initialize path
data = open(path).read
if data.include? 'DslState = 0'
@state = :disconnected
elsif data =~ /ipaddress = "([.0-9]+)"/
@ip = $1
@state = :connected
else
@state = :pending
end
@username = $1 if data =~ /usernameContent = "([^&;]+)";/
@devices = []
device = {}
data.scan(/device([A-Za-z]+) = "(.+)";/).each do |pair|
device[pair[0]] = pair[1]
if pair[0] == 'MAC'
@devices << Device.new(device)
device = {}
end
end
end
end
class Device
attr_reader :netbios, :name, :mac, :url, :ip, :connection, :connected, :type
ConnectionNames = %w{ethernet wireless USB unknown DMZ}
TypeNames = ['router', 'computer', 'network storage device', 'VoIP adapter', 'printer', 'camera', 'media adapter', 'device', 'unknown device']
def connection_type
ConnectionNames[@connection]
end
def type_name
TypeNames[@type]
end
alias connected? connected
def initialize(hash)
@netbios = hash['HasNBios'] == '1'
@name = hash['Name']
@mac = hash['MAC']
@url = hash['URL']
@ip = hash['IP']
@connection = hash['ConnectType'].to_i
@connected = hash['State'] == '0'
@type = hash['Type'].to_i
end
def ==(other)
@netbios == other.netbios && @name == other.name && @mac == other.mac &&
@url == other.url && @ip == other.ip && @connection == other.connection &&
@connected == other.connected && @type == other.type
end
end
end
Jump to Line
Something went wrong with that request. Please try again.