Skip to content

Instantly share code, notes, and snippets.

@crohr
Created March 18, 2010 14:28
Show Gist options
  • Save crohr/336398 to your computer and use it in GitHub Desktop.
Save crohr/336398 to your computer and use it in GitHub Desktop.
def launch_server
server = TCPServer.new(7910)
while (session = server.accept)
Thread.new do
begin
command = session.readline.chomp
rescue
# If input is a ^c close client session and wait for a new one
session.close
next
end
# may be changed with 00:16:3E:XX:XX:XX ... if wanted
if command =~ /^([a-fA-F0-9]{2}:){5}([a-fA-F0-9]{2})$/
ip = omshell(command)
if ip
name = nsupdate(ip,parse(command))
session.puts ip+"\t"+name+".virtual"
else
session.puts "ip address not attributed"
end
elsif command =~ /^([a-fA-F0-9]{2}):([a-fA-F0-9]{2}):([a-fA-F0-9]{2}):([a-fA-F0-9]{2}):([a-fA-F0-9]{2}):([a-fA-F0-9]{2}) ([\w\-_]+)$/
matching = Regexp.last_match
mac = matching[1..6].join(':')
name = matching[7]
puts mac
puts name
ip = omshell(mac)
if ip
if name = nsupdate(ip,name)
session.puts ip+"\t"+name+".virtual"
else
session.puts "can't setup hostname"
end
else
session.puts "ip address not attributed"
end
else
session.puts "bad command : xenconf mac [hostname]"
end
session.close
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment