(self, ip)
| 88 | (self.curEndIp,) = struct.unpack("I", buf) |
| 89 | |
| 90 | def getIpAddr(self, ip): |
| 91 | L = 0 |
| 92 | R = self.indexCount - 1 |
| 93 | while L < R - 1: |
| 94 | M = int((L + R) / 2) |
| 95 | self.setIpRange(M) |
| 96 | if ip == self.curStartIp: |
| 97 | L = M |
| 98 | break |
| 99 | if ip > self.curStartIp: |
| 100 | L = M |
| 101 | else: |
| 102 | R = M |
| 103 | self.setIpRange(L) |
| 104 | # version information, 255.255.255.X, urgy but useful |
| 105 | if ip & 0xffffff00 == 0xffffff00: |
| 106 | self.setIpRange(R) |
| 107 | if self.curStartIp <= ip <= self.curEndIp: |
| 108 | address = self.getAddr(self.curEndIpOffset) |
| 109 | # 把GBK转为utf-8 |
| 110 | address = text_(address) |
| 111 | else: |
| 112 | address = text_("未找到该IP的地址") |
| 113 | return address |
| 114 | |
| 115 | def getIpRange(self, ip): |
| 116 | self.getIpAddr(ip) |
no test coverage detected