Last active
February 8, 2022 15:35
-
-
Save DanAmt/132e8dd4fd5abe4f982ca6dab64784f6 to your computer and use it in GitHub Desktop.
Here we can test a socket without netstat telnet and so on
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
#For socket checking in case no tools around except python | |
import socket | |
import sys | |
if len(sys.argv) != 3: | |
print("Usage: " + sys.argv[0] + " <IP or Name> <Port>") | |
sys.exit(2) | |
s = socket.socket() | |
address = str(sys.argv[1]) | |
port = int(sys.argv[2]) # port number is a number, not string | |
ipaddress = socket.gethostbyname(sys.argv[1]) | |
print("IPaddress checked is " + ipaddress + " " + str(port) ) | |
result = s.connect_ex((address, port)) | |
s.close() | |
if result: | |
print("Problem with socket!") | |
else: | |
print("Socket ok!") | |
print("Returnvalue is " + str(result)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment