You correctly specify the grouping you want for your regular expression, but you do not use it when printing it. A.
Your regex:
mac = re.match /Device ID: ([\S]+)/
and that matches the whole line Device ID: SEP1C17D3415659by putting the right part ( SEP1C17D3415659) in the group so you can get it later. However, you print it with
o.puts mac
This gives the whole match, not just the group. Instead, you want:
o.puts mac[1]
which indicates only the group.
, , puts . , , - :
o.print "#{mac[1]} #{ip[1]}\n"
.
Edit:
net/telnet , , , , , . , , , nil mac ip, "undefind method []" .
, :
o.print "#{mac[1]} #{ip[1]}\n" unless mac.nil?
, , , , . , , , :
run.each_line do |line|
match = line.match /^Device ID: ([\S]+), IP address: ([\S]+)$/
next unless match
o.print "#{match[1]} #{match[2]}\n"
end