Revision 05edafd3 lib/netutils.py
b/lib/netutils.py | ||
---|---|---|
267 | 267 |
return hostname |
268 | 268 |
|
269 | 269 |
|
270 |
def ValidatePortNumber(port): |
|
271 |
"""Returns the validated integer port number if it is valid. |
|
272 |
|
|
273 |
@param port: the port number to be validated |
|
274 |
|
|
275 |
@raise ValueError: if the port is not valid |
|
276 |
@rtype: int |
|
277 |
@return: the validated value. |
|
278 |
|
|
279 |
""" |
|
280 |
|
|
281 |
try: |
|
282 |
port = int(port) |
|
283 |
except TypeError: |
|
284 |
raise errors.ProgrammerError("ValidatePortNumber called with non-numeric" |
|
285 |
" type %s." % port.__class__.__name__) |
|
286 |
except ValueError: |
|
287 |
raise ValueError("Invalid port value: '%s'" % port) |
|
288 |
|
|
289 |
if not 0 < port < 2 ** 16: |
|
290 |
raise ValueError("Invalid port value: '%d'" % port) |
|
291 |
|
|
292 |
return port |
|
293 |
|
|
294 |
|
|
270 | 295 |
def TcpPing(target, port, timeout=10, live_port_needed=False, source=None): |
271 | 296 |
"""Simple ping implementation using TCP connect(2). |
272 | 297 |
|
Also available in: Unified diff