I am trying to run the script. But when I pass an IP which is not in the network to the s.connect() function. It dosen’t respond, the script goes on hold, so I want to end the check on IP, if the Ip is not found in the network. Does anyone have an idea, on how to proceed.
`import socket
def getBanner(ip,port):
socket.setdefaulttimeout(1)
if(s.connect((ip,port))):
banner = s.recv(1024).decode()
return banner
else:
return "Nothing"
def main():
ip = "192.168.152."+str(0)
banner = getBanner(ip,21)
print(banner)
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
main()`
New contributor
Bhuvanesh A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.