Previously we have a nodejs script to test the connectivity between Apigee SaaS and Target Servers. However, post recent upgrade - nodejs is not compatible with present Apigee SaaS version. We tried creating a Python script - also a separate java script instead of nodejs - but we are seeing the below problem.
-
When we try the script locally - have no trouble connecting to any servers/websites - and throws errors for invalid hosts - as expected
-
However, when we deploy this script as Proxy to test our target servers - we get success for all valid & invalid hosts.
Can some one guide if I am missing anything here?
#!/usr/bin/python
import socket
import time
def isValidHost(domain):
try:
socket.gethostbyname(domain)
return True
except socket.gaierror:
# this means could not resolve the host
print("there was an error resolving the host")
return False
def isConnected(domain, port, retry):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout)
s.connect((domain, int(port)))
s.shutdown(socket.SHUT_RDWR)
print("connected")
return True
except BaseException:
print(retry)
print('Error occurred while establishing connection...')
return False
if isValidHost(domain):
domain = "google.com"
port = 443
retry = 2
delay = 5
timeout = 3
while (retry != 0):
if isConnected(domain, port, retry):
retry = 0
else:
retry = retry - 1
else:
print('Invalid host')