File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pyfiglet
2
+ import sys
3
+ import socket
4
+ from datetime import datetime
5
+
6
+ ascii_banner = pyfiglet .figlet_format ("PORT SCANNER" )
7
+ print (ascii_banner )
8
+
9
+ # Defining a target
10
+ if len (sys .argv ) == 2 :
11
+
12
+ # translate hostname to IPv4
13
+ target = socket .gethostbyname (sys .argv [1 ])
14
+ else :
15
+ print ("Invalid ammount of Argument" )
16
+
17
+ # Add Banner
18
+ print ("-" * 50 )
19
+ print ("Scanning Target: " + target )
20
+ print ("Scanning started at:" + str (datetime .now ()))
21
+ print ("-" * 50 )
22
+
23
+ try :
24
+
25
+ # will scan ports between 1 to 65,535
26
+ for port in range (1 ,65535 ):
27
+ s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
28
+ socket .setdefaulttimeout (1 )
29
+
30
+ # returns an error indicator
31
+ result = s .connect_ex ((target ,port ))
32
+ if result == 0 :
33
+ print ("Port {} is open" .format (port ))
34
+ s .close ()
35
+
36
+ except KeyboardInterrupt :
37
+ print ("\n Exitting Program !!!!" )
38
+ sys .exit ()
39
+ except socket .gaierror :
40
+ print ("\n Hostname Could Not Be Resolved !!!!" )
41
+ sys .exit ()
42
+ except socket .error :
43
+ print ("\ Server not responding !!!!" )
44
+ sys .exit ()
Original file line number Diff line number Diff line change
1
+ #This script implements Substitution Cipher
2
+ #The key for encrypting the message must be passed as a Command line argument in the form of a csv file
3
+
4
+ #To run the script from terminal, run
5
+ #python3 substitution_cipher.py "path_to_csv_file_containing_the_key"
6
+
7
+ import csv
8
+ import sys
9
+
10
+ def get_key ():
11
+ key = dict ()
12
+ with open (sys .argv [1 ] , 'r' ) as file :
13
+ reader = csv .reader (file )
14
+ for row in reader :
15
+ key [row [0 ].strip ()] = row [1 ].strip ()
16
+ return (key )
17
+
18
+ def encrypt ():
19
+ key = get_key ()
20
+ message = input ("Enter the message " )
21
+ encrypted_message = ''
22
+ for letter in message :
23
+ try :
24
+ encrypted_message += key [letter ]
25
+ except :
26
+ alert = "Your key does not have a suitable match for " + letter + "\n Please update your key and try again!"
27
+ return (- 1 , alert )
28
+ return (0 , encrypted_message )
29
+
30
+ if __name__ == "__main__" :
31
+ exit_code , message = encrypt ()
32
+ if (exit_code == 0 ):
33
+ print ("The encrypted message is " , message )
34
+ else :
35
+ print (message )
You can’t perform that action at this time.
0 commit comments