Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find for people in the local area network
require "pp"
def arp
result = `arp -a`
lines = result.split("\n")
address_table = Array.new
lines.each do |line|
ip = line[/\((.*?)\)/,1]
mac = line[/at\ (.*?)\ on/,1]
next if mac == "(incomplete)"
next unless ip.index(/^192/)
address_table.push([ip, mac])
end
return address_table.uniq
end
def search_device(local_devices)
find_devices = Array.new
local_devices.each do |local_device|
$devices.each do |d|
find_devices.push(local_device.push(d[2])) if d[0] == local_device[1]
end
end
return find_devices.uniq
end
def find(user_name)
# Create device list
device_name = ""
$peoples.each do |people|
if people[0] == user_name
device_name = people[1]
end
end
# Find device
find = false
device_name.each do |d|
$find_devices.each do |fd|
if fd[2] == d
find = true
end
end
end
print(user_name + "\t" + find.to_s + "\n")
return find
end
$devices = [["xx:xx:xx:xx:xx:xx", "iPhone", "Tom'siPhone"],
["xx:xx:xx:xx:xx:xx", "iPhone", "Alice'siPhone"],
["xx:xx:xx:xx:xx:xx", "iPad", "Tom'siPad"],
["xx:xx:xx:xx:xx:xx", "iPad", "Tom'siPad"],
["xx:xx:xx:xx:xx:xx", "Mac", "Tom'sMac"],
["xx:xx:xx:xx:xx:xx", "Mac", "Tom'sMac"]]
$peoples = [["tom", ["Tom'siPhone"]],
["alice", ["Alice'siPhone"]]]
pp local_devices = arp
pp $find_devices = search_device(local_devices)
find("tom")
find("alice")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.