diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-15 11:28:10 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-15 11:28:10 +0000 |
commit | 8ea13fef151d9bcd3f56a3320cd19fb0a838648d (patch) | |
tree | 70cfecebd842513c6997d4d6c12a592b982a40ea /lib/custodian/alerter.rb | |
parent | 8a24619f05de1f52a65fdd36e7a8a6643a887953 (diff) |
Don't resolve IPs
Diffstat (limited to 'lib/custodian/alerter.rb')
-rw-r--r-- | lib/custodian/alerter.rb | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb index f5caa6a..8bbd47e 100644 --- a/lib/custodian/alerter.rb +++ b/lib/custodian/alerter.rb @@ -43,29 +43,43 @@ class Alerter # resolved = nil + # - # Resolve the target to an IP + # Resolve the target to an IP, unless it is already an address. # - begin - Socket.getaddrinfo(target, 'echo').each do |a| - resolved = a[3] if ( a ) + if ( ( target =~ /^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) || + ( target =~ /^([0-9a-f:]+)$/ ) ) + resolved = target + else + begin + Socket.getaddrinfo(target, 'echo').each do |a| + resolved = a[3] if ( a ) + end + rescue SocketError + resolved = nil end - rescue SocketError end + # + # Did we get an error? + # return "" unless ( !resolved.nil? ) + + # + # Make any HTTP target a link in the details. + # if ( host =~ /^http/ ) host = "<a href=\"#{host}\">#{host}</a>" end # - # Test trange + # Test trange, and format the appropriate message. # if ( BYTEMARK_RANGES.any?{|range| range.include?(IPAddr.new(resolved.to_s))} ) return "<p>#{host} resolves to <tt>#{resolved}</tt> which is inside the Bytemark network.</p>" else - return "<p>#{host} resolves to <tt>#{resolved}</tt> which <b>is not</b> inside the Bytemark network.</p>" + return "<p>#{host} resolves to <tt>#{resolved}</tt> which is not inside the Bytemark network.</p>" end end |