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