Jelajahi Sumber

more debug, better blocks

Paul Klumpp 11 tahun lalu
induk
melakukan
0864999ef6
1 mengubah file dengan 27 tambahan dan 18 penghapusan
  1. 27 18
      em_server.rb

+ 27 - 18
em_server.rb

@@ -319,7 +319,7 @@ module CentralProtocolHandler
           if source =~ /^qw:\/\/(.+):(\d+)(.*)$/
             # ip address is 15 in length
             iphost = $1
-            domainname = iphost # set a default
+            targetname = iphost # set a default
             ipport = $2
             rest = $3
 
@@ -329,21 +329,29 @@ module CentralProtocolHandler
               c = GeoIP.new('GeoIP.dat').country(iphost)[3].to_s.downcase
               rest.prepend " #{c}" unless c.nil? || c.empty?
 
-              # get hostname from a qw status packet! perhaps there's a DNS name inside, which we can use! fixme
-              hum = qwstatus(iphost, ipport)
-              p hum
-              if hum["hostname"] =~ /([\w\.]{3,}\.\w{2,4})/
-                hostnamedns = $1
-                ip_of_hostnamedns = Resolv.getaddress(hostnamedns)
-
-                if ip_of_hostnamedns && (ip_of_hostnamedns == iphost)
-                  # ok, we take it.
-                  put_log "ok, we take #{hostnamedns} for #{iphost} here.."
-                  domainname = hostnamedns
+
+              # resolve it to a dns name (reverse lookup)
+              if targetname == iphost # if it is still default
+                put_log "Ip not resolved .. we try hostname dns finder"
+                # get hostname from a qw status packet! perhaps there's a DNS name inside, which we can use! fixme
+                status = qwstatus(iphost, ipport)
+                p status
+                if status["hostname"] =~ /([\w\.]{3,}\.\w{2,4})/
+                  hostnamedns = $1.downcase
+                  ip_of_hostnamedns = Resolv.getaddress(hostnamedns)
+                  if ip_of_hostnamedns && (ip_of_hostnamedns == iphost)
+                    # ok, we take it.
+                    put_log "Ok, we take #{hostnamedns} for #{iphost} here.."
+                    targetname = hostnamedns
+                  else
+                    put_log "Found #{hostnamedns} but #{ip_of_hostnamedns} is not #{iphost}"
+                  end
                 end
+              end
 
-              else
-                # resolve it to a dns name
+              # resolve it to a dns name (reverse lookup)
+              if targetname == iphost # if it is still default
+                put_log "Still no resolve .. we try reverse dns lookup"
                 resulting_name = Resolv.getname(iphost)
                 if resulting_name
                   # if the resulting dns name...
@@ -356,14 +364,15 @@ module CentralProtocolHandler
                     put_log "#{resulting_name.split(".").size}"
                     put_log "#{resulting_name.scan(/\d/).size}"
                   else
-                    domainname = resulting_name
-                  end
-                end # of resolving
+                    targetname = resulting_name
+                  end # of Resolv.getname
+                end
+
               end
 
             end # if ip is x.x.x.x
 
-            source = "qw://#{domainname}:#{ipport}#{rest}"
+            source = "qw://#{targetname}:#{ipport}#{rest}"
           end # of if source qw://x.x.x.x:portzzz
 
           # resolve