Skip to content

Instantly share code, notes, and snippets.

@strangnet
Created July 12, 2012 15:59
Show Gist options
  • Save strangnet/3099017 to your computer and use it in GitHub Desktop.
Save strangnet/3099017 to your computer and use it in GitHub Desktop.
Netstat loop to log the udp out to port 1
#!/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
@strangnet
Copy link
Author

Run with

ruby netstat.rb >/tmp/netstat.log &

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment