mirror of
https://github.com/python/cpython.git
synced 2026-01-04 14:32:21 +00:00
modify testGetServByName so it tries a few different protocols. In this day
and age of rampant computer breakins I imagine there are plenty of systems with telnet disabled. Successful check of at least one getservbyname() call is required for success
This commit is contained in:
parent
ea0c3828c0
commit
d3c884d4ea
1 changed files with 17 additions and 5 deletions
|
|
@ -260,11 +260,23 @@ def testNtoH(self):
|
|||
def testGetServByName(self):
|
||||
"""Testing getservbyname()."""
|
||||
if hasattr(socket, 'getservbyname'):
|
||||
socket.getservbyname('telnet', 'tcp')
|
||||
try:
|
||||
socket.getservbyname('telnet', 'udp')
|
||||
except socket.error:
|
||||
pass
|
||||
# try a few protocols - not everyone has telnet enabled
|
||||
found = 0
|
||||
for proto in ("telnet", "ssh", "www", "ftp"):
|
||||
try:
|
||||
socket.getservbyname(proto, 'tcp')
|
||||
found = 1
|
||||
break
|
||||
except socket.error:
|
||||
pass
|
||||
try:
|
||||
socket.getservbyname(proto, 'udp')
|
||||
found = 1
|
||||
break
|
||||
except socket.error:
|
||||
pass
|
||||
if not found:
|
||||
raise socket.error
|
||||
|
||||
def testDefaultTimeout(self):
|
||||
"""Testing default timeout."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue