Created
May 5, 2012 13:09
-
-
Save til/2602276 to your computer and use it in GitHub Desktop.
Simple script to diagnose network problems of local computer
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
# Simple script to diagnose network problems of the local computer: | |
# runs a couple of checks and aborts on first failure. This should | |
# help to find the cause of the problem quicker. | |
def headline(name) | |
puts | |
puts "--- #{name} ".ljust(80, '-') | |
end | |
def run(cmd) | |
puts | |
puts cmd | |
output = `#{cmd}` | |
puts output | |
if $?.success? | |
output | |
else | |
abort 'FAIL' | |
end | |
end | |
headline "Wlan" | |
wlan = run "iwconfig wlan0" | |
if wlan =~ /Link Quality=([1-9][0-9]\/\d\d)/ | |
puts "OK, link quality #{$1}" | |
else | |
puts "No Wlan, who cares" | |
end | |
headline "Route" | |
routes = run "route -n" | |
gw = routes.split("\n").grep(/^\s*0\.0\.0\.0/).first.split(" ")[1] | |
puts "OK, gateway is #{gw}" | |
headline "Ping gateway" | |
run "ping -q -c 1 #{gw}" | |
puts "OK" | |
headline "Ping outside IP" | |
run "ping -q -c 1 141.1.1.1" | |
puts "OK" | |
headline "Nameserver configured" | |
resolv = run "cat /etc/resolv.conf" | |
puts resolv | |
if resolv =~ /nameserver\s+(\S+)/ | |
nameserver = $1 | |
puts "OK, nameserver is #{nameserver}" | |
else | |
abort 'Not found' | |
end | |
headline "Ping nameserver" | |
run "ping -q -c 1 #{nameserver}" | |
puts "OK" | |
headline "Ping heise" | |
run "ping -q -c 1 heise.de" | |
puts "OK" | |
headline "Ping tils.net" | |
run "ping -q -c 1 tils.net" | |
puts "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: