Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

Create check_ports_socket.py

Abdul Wahab Junaid9e9e45aacaf5
diff --git a/Python Tools/Port_Scanning/check_ports_socket.py b/Python Tools/Port_Scanning/check_ports_socket.py
new file mode 100644
index 0000000..6f3dc07
--- /dev/null
+++ b/Python Tools/Port_Scanning/check_ports_socket.py
@@ -0,0 +1,22 @@
+#!/usr/bin/python
+
+import socket
+import sys
+
+def checkPortsSocket(ip,portlist):
+ try:
+ for port in portlist:
+ sock= socket.socket(socket.AF_INET,socket.SOCK_STREAM)
+ sock.settimeout(5)
+ result = sock.connect_ex((ip,port))
+ if result == 0:
+ print ("Port {}: \t Open".format(port))
+ else:
+ print ("Port {}: \t Closed".format(port))
+ sock.close()
+ except socket.error as error:
+ print (str(error))
+ print ("Connection error")
+ sys.exit()
+
+checkPortsSocket('localhost',[21,22,80,8080,443])