• R/O
  • SSH

コミット

よく使われているワード(クリックで追加)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

A small utility to fetch information about IPv6 addresses and possibly also any associated IPv4 address.


コミットメタ情報

リビジョン6d535bbddf0c15ce53ac4f64a91a2f7d315d484c (tree)
日時2017-06-06 15:56:53
作者Eric Hopper <hopper@omni...>
コミッターEric Hopper

ログメッセージ

Hopefully this is now Python 2/3 agnostic.

変更サマリ

差分

diff -r 40ca37f347fa -r 6d535bbddf0c py_ipv6_info
--- a/py_ipv6_info Sat Dec 31 02:40:04 2016 -0800
+++ b/py_ipv6_info Mon Jun 05 23:56:53 2017 -0700
@@ -1,5 +1,6 @@
11 #!/usr/bin/python
22
3+from __future__ import print_function
34 import socket
45 import sys
56 import struct
@@ -35,12 +36,12 @@
3536
3637 def analyze_ipv4(s, raw, addrtype):
3738 numaddr = struct.unpack('!L', raw)[0]
38- print "Got IPv4 address: %s\n - in raw hex 0x%08x" % (s, numaddr)
39+ print("Got IPv4 address: %s\n - in raw hex 0x%08x" % (s, numaddr))
3940 if addrtype == TYPE_TEREDONAT:
40- print " - in obfuscated hex 0x%08x" % (numaddr ^ 0xffffffff,)
41+ print(" - in obfuscated hex 0x%08x" % (numaddr ^ 0xffffffff,))
4142 canon = socket.inet_ntop(socket.AF_INET, raw)
4243 if canon != s:
43- print " - Canonical %s" % (canon,)
44+ print(" - Canonical %s" % (canon,))
4445 else:
4546 canon = s
4647 revname = dns.reversename.from_address(canon)
@@ -50,8 +51,8 @@
5051 except dns.exception.DNSException:
5152 pass
5253 if addrtype == TYPE_6TO4:
53- print " - The 6to4 IPv6 prefix is 2002:%x:%x::/48" % \
54- (numaddr >> 16, numaddr & 0xffff)
54+ print(" - The 6to4 IPv6 prefix is 2002:%x:%x::/48" % \
55+ (numaddr >> 16, numaddr & 0xffff))
5556 while (answer is None) and (len(revname) > 4):
5657 revname = revname.parent()
5758 try:
@@ -59,25 +60,25 @@
5960 except dns.exception.DNSException:
6061 pass
6162 if answer is None:
62- print " - *** Reverse lookup failed for %s ***" % (revname,)
63+ print(" - *** Reverse lookup failed for %s ***" % (revname,))
6364 else:
6465 if len(revname) != 7:
65- print " - *** The initial PTR lookup failed ***"
66- print " - %s" % (revname,)
66+ print(" - *** The initial PTR lookup failed ***")
67+ print(" - %s" % (revname,))
6768 for result in answer.rrset:
68- print " - %s: %s" % (dnstype.to_text(result.rdtype), result)
69+ print(" - %s: %s" % (dnstype.to_text(result.rdtype), result))
6970
7071 def analyze_ipv6(s, raw):
7172 numaddr = struct.unpack('!QQ', raw)
7273 numaddr = numaddr[0] * 2**64 + numaddr[1]
73- print "Got IPv6 address: %s\n - in raw hex 0x%016x" % (s, numaddr)
74+ print("Got IPv6 address: %s\n - in raw hex 0x%016x" % (s, numaddr))
7475 canon = socket.inet_ntop(socket.AF_INET6, raw)
7576 if canon != s:
76- print " - Canonical %s" % (canon,)
77+ print(" - Canonical %s" % (canon,))
7778 else:
7879 canon = s
7980 if ((numaddr >> 125) & 0x7) != 1:
80- print " - === Not a globally routable address"
81+ print(" - === Not a globally routable address")
8182 return
8283 revname = dns.reversename.from_address(canon)
8384 answer = None
@@ -93,37 +94,39 @@
9394 pass
9495 if answer is not None:
9596 if len(revname) != 35:
96- print " - *** The initial PTR lookup failed ***"
97- print " - %s" % (revname,)
97+ print(" - *** The initial PTR lookup failed ***")
98+ print(" - %s" % (revname,))
9899 for result in answer.rrset:
99- print " - %s: %s" % (dnstype.to_text(result.rdtype), result)
100+ print( " - %s: %s" % (dnstype.to_text(result.rdtype), result))
100101 else:
101- print " - *** Unable to reverse lookup any information ***"
102+ print(" - *** Unable to reverse lookup any information ***")
102103 if (numaddr >> 112) == 0x2002:
103104 raw4 = struct.pack('!L', (numaddr >> 80) & 0xffffffff)
104105 s4 = socket.inet_ntop(socket.AF_INET, raw4)
105- print " - 6to4 address %s" % (s4,)
106- print "-+-+-+-"
106+ print(" - 6to4 address %s" % (s4,))
107+ print("-+-+-+-")
107108 analyze_ipv4(s4, raw4, TYPE_6TO4)
108- print "-+-+-+-"
109+ print("-+-+-+-")
109110 elif (numaddr >> 96) == 0x20010000:
110111 rawnat4 = struct.pack('!L', (numaddr & 0xffffffff) ^ 0xffffffff)
111112 rawserv4 = struct.pack('!L', (numaddr >> 64) & 0xffffffff)
112113 snat4 = socket.inet_ntop(socket.AF_INET, rawnat4)
113114 sserv4 = socket.inet_ntop(socket.AF_INET, rawserv4)
114- print " - Teredo NAT (the public IPv4 address): %s" % (snat4,)
115- print " - Teredo server (assigner of the IPv6 address): %s" % (sserv4,)
116- print "-+-+-+- (Teredo NAT (the public IPv4 address of the system))"
115+ print(" - Teredo NAT (the public IPv4 address): %s" % (snat4,))
116+ print(" - Teredo server (assigner of the IPv6 address): %s" % (sserv4,))
117+ print("-+-+-+- (Teredo NAT (the public IPv4 address of the system))")
117118 analyze_ipv4(snat4, rawnat4, TYPE_TEREDONAT)
118- print "-+-+-+- (Teredo server (probably not important))"
119+ print("-+-+-+- (Teredo server (probably not important))")
119120 analyze_ipv4(sserv4, rawserv4, TYPE_TEREDOSERVER)
120121
121122 if __name__ == '__main__':
122123 if len(sys.argv) > 1:
123- print "==========="
124+ print("===========")
124125 for x in sys.argv[1:]:
125126 try:
126127 analyze_addr(x)
127- except BadAddress, a:
128- print >>sys.stderr, "%s doesn't appear to be a valid numeric IPv4 or IPv6 address." % (x, )
129- print "==========="
128+ except BadAddress as a:
129+ print("%s doesn't appear to be a valid numeric IPv4 or IPv6 address." \
130+ % (x, ),
131+ file=sys.stderr)
132+ print("===========")