Ansgar Wiechers points out that known_hosts (at least OpenSSH's) has grown a
authorjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sun, 26 Apr 2009 23:44:28 +0000 (23:44 +0000)
committerjacob <jacob@cda61777-01e9-0310-a592-d414129be87e>
Sun, 26 Apr 2009 23:44:28 +0000 (23:44 +0000)
means of specifying port numbers, so we should support that.

git-svn-id: svn://svn.tartarus.org/sgt/putty@8519 cda61777-01e9-0310-a592-d414129be87e

contrib/kh2reg.py

index 4e88186..4872aec 100755 (executable)
@@ -132,9 +132,13 @@ for line in fileinput.input(args):
                 sys.stderr.write("Skipping hashed hostname '%s'\n" % host)
                 continue
             else:
-                # Slightly bizarre key format: 'type@port:hostname'
-                # As far as I know, the input never specifies a port.
-                port = 22
+                m = re.match (r"\[([^]]*)\]:(\d*)$", host)
+                if m:
+                    (host, port) = m.group(1,2)
+                    port = int(port)
+                else:
+                    port = 22
+                # Slightly bizarre output key format: 'type@port:hostname'
                 # XXX: does PuTTY do anything useful with literal IP[v4]s?
                 key = keytype + ("@%d:%s" % (port, host))
                 value = string.join (map (longtohex, magicnumbers), ',')