(ip, family)
| 157 | |
| 158 | |
| 159 | def islocal(ip, family): |
| 160 | sock = socket.socket(family) |
| 161 | try: |
| 162 | try: |
| 163 | sock.bind((ip, 0)) |
| 164 | except socket.error: |
| 165 | _, e = sys.exc_info()[:2] |
| 166 | if e.args[0] == errno.EADDRNOTAVAIL: |
| 167 | return False # not a local IP |
| 168 | else: |
| 169 | raise |
| 170 | finally: |
| 171 | sock.close() |
| 172 | return True # it's a local IP, or there would have been an error |
| 173 | |
| 174 | |
| 175 | def family_ip_tuple(ip): |
no test coverage detected