Created
July 12, 2012 15:59
-
-
Save strangnet/3099017 to your computer and use it in GitHub Desktop.
Netstat loop to log the udp out to port 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ruby | |
while (true) | |
f = IO.popen('netstat -anp udp') | |
found = false | |
while (line = f.gets) | |
linesplit = line.split | |
if (/udp/ =~ linesplit[0]) | |
local = linesplit[3] | |
foreign = linesplit[4] | |
port = foreign.split(".").last | |
if (port == "1") | |
found = true | |
print local + " " + foreign + "\n" | |
end | |
end | |
end | |
f.close | |
if (found) | |
puts Time.now | |
end | |
sleep(5) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run with