Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aab0845

Browse files
Merge pull request avinashkranjan#368 from mafiaguy/master
Port Scanning Script added
2 parents 94c9e1b + 470545a commit aab0845

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

‎PortScanning/README.md

196 Bytes
(追記)

ThePortScanningTool

(追記ここまで)
(追記) (追記ここまで)(追記)

A python scripting which help to do port scanning of a particular ip.

(追記ここまで)

‎PortScanning/portscanningscript.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import socket
2+
import subprocess
3+
import sys
4+
from datetime import datetime
5+
6+
subprocess.call('cls', shell=True)
7+
8+
# Ask for input
9+
remoteServer = input("Enter a remote host to scan: ")
10+
remoteServerIP = socket.gethostbyname(remoteServer)
11+
12+
# Print a nice banner with information on which host we are about to scan
13+
print ("-" * 60)
14+
print ("Please wait, scanning remote host", remoteServerIP)
15+
print ("-" * 60)
16+
17+
# Check what time the scan started
18+
t1 = datetime.now()
19+
20+
# Using the range function to specify ports (here it will scans all ports
21+
22+
# We also put in some error handling for catching errors
23+
try:
24+
for port in range(1,1025):
25+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
26+
result = sock.connect_ex((remoteServerIP, port))
27+
if result == 0:
28+
print ("Port {}: Open".format(port))
29+
sock.close()
30+
except KeyboardInterrupt:
31+
print ("You pressed Ctrl+C")
32+
sys.exit()
33+
34+
except socket.gaierror:
35+
print ('Hostname could not be resolved. Exiting')
36+
sys.exit()
37+
38+
except socket.error:
39+
print ("Couldn't connect to server")
40+
sys.exit()
41+
42+
# Checking the time again
43+
t2 = datetime.now()
44+
45+
# Calculates the difference of time, to see how long it took to run the script
46+
total = t2 - t1
47+
48+
print ('Scanning Completed in: ', total)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /