Skip to content

Commit

Permalink
enhance ip addr lookup for ssh access method
Browse files Browse the repository at this point in the history
  • Loading branch information
tomweber-sas committed Dec 20, 2024
1 parent 678632e commit 4a4f702
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions saspy/sasiostdio.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,24 +240,38 @@ def __init__(self, session, **kwargs):

self._prompt = session._sb.sascfg._prompt

if localhost is not None:
self.hostip = localhost
else:
self.hostip = socks.gethostname()
try:
x = subprocess.Popen(('nslookup', self.hostip), stdout=subprocess.PIPE)
z = x.stdout.read()
ip = z.rpartition(b'Address:')[2].strip().decode()
if self.ssh:
if localhost is not None:
self.hostip = localhost
else:
self.hostip = socks.gethostname()
print('No localhost, hostip=', str(self.hostip))
try:
socks.gethostbyaddr(ip)
self.hostip = ip
x = subprocess.Popen(('nslookup', self.hostip), stdout=subprocess.PIPE)
z = x.stdout.read()
ip = z.rpartition(b'Address:')[2].strip().decode()
try:
print('nslookup ip=', str(ip))
socks.gethostbyaddr(ip)
self.hostip = ip
except:
sock = socks.socket()
sock.bind(('',0))
sock.settimeout(1)
try:
sock.connect((self.host, 22))
except:
pass
print('sock=', str(sock))
ip = sock.getsockname()[0]
self.hostip = ip
print('self.hostip fom connect is ip=', str(ip))
sock.close()
x.stdout.close()
x.terminate()
x.wait(1)
except:
pass
x.stdout.close()
x.terminate()
x.wait(1)
except:
pass

return

Expand Down

0 comments on commit 4a4f702

Please sign in to comment.