-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonScript.py
More file actions
38 lines (28 loc) · 1.28 KB
/
pythonScript.py
File metadata and controls
38 lines (28 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//A simple Port Scanning script using Python.
// This script connects to a remote port on a system to see if it's listening.
// At the end of the exec, the user gets a message telling him if the port is open or colsed.
// Attention: please take care to chmod the script before trying to run it.
// Point to the Python interpreter.
#!/usr/bin/python
// Import socket library, which is useful to perform networking tasks.
import socket
// Gets the IP address, and assigns it to the var ip.
ip = raw_input("Enter the ip: ")
// Gets the socket number as an integer, and assigns it to the var port.
port = input("Enter the port: ")
// Creates a network socket and assigns it to variable s.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
// Invokes the function connect_ex to connect to the remote host.
// If the connection succeeds the function returns the value 0.
// The value 0 is evaluated by the if statement as false.
// Otherwise, if the returned value is true, or a poitive number,
// that will mean that the port is closed.
if s.connect_ex((ip, port)):
print "Port", port, "is closed"
else:
print "Port", port, "is open"
// Below is an example of code execution on port 80:
// root@kali:~/# ./pythonscript.py
// Enter the ip: 192.168.100.10
// Enter the port: 80
// Port 80 is open