diff --git a/Final Version CW2.py b/Final Version CW2.py index 4df1aca..efac392 100644 --- a/Final Version CW2.py +++ b/Final Version CW2.py @@ -2,6 +2,7 @@ def menu(): while True: print("The code will now check what operating system you are using") from sys import platform + import os, socket if platform == "linux" or platform == "linux2": print("Operating system = Linux") print("Please Select The Process You Require") @@ -13,7 +14,6 @@ def menu(): option = (input( "\n1. IP Address \n2. Username\n3. Hostname\n4. Port Scan \n5. UID 5\n6. Process Id\n7. GID")) if option == "1": - import socket hostname = socket.gethostname() ipv4 = socket.gethostbyname(hostname) print("\nWhich output would you like to use") @@ -52,7 +52,6 @@ def menu(): output_file.write(username) exit() elif option == "3": - import socket print("\nWhich output would you like to use") output = (input("1. Console\n2. File\n")) if output == "1": @@ -69,7 +68,6 @@ def menu(): output_file.write(socket.gethostname()) exit() elif option == "4": - import socket socket.setdefaulttimeout(2) s = socket.socket() target_ip = input('Enter IP in single quotes: ') @@ -87,7 +85,6 @@ def menu(): elif option == "n": exit() elif option == "5": - import os uid = os.getuid() print("\nWhich output would you like to use") output = (input("1. Console\n2. File\n")) @@ -105,7 +102,6 @@ def menu(): print(uid, file=output_file) exit() elif option == "6": - import os pid = os.getpid() print("\nWhich output would you like to use") output = (input("1. Console\n2. File\n")) @@ -123,15 +119,19 @@ def menu(): print(pid, file=output_file) exit() elif option == "7": - import grp, pwd - user = getpass.getuser() - groups = [g.gr_name for g in grp.getgrall() if user in g.gr_mem] - gid = pwd.getpwnam(user).pw_gid - groups.append(grp.getgrgid(gid).gr_name) + gid = os.getgid() + print(gid) + + print("Do you want to quit or return to menu?") + option = (input("y or n\n")) + if option == "y": + menu() + elif option == "n": + exit() print("\nWhich output would you like to use") output = (input("1. Console\n2. File\n")) if output == "1": - print(groups) + print(gid) print("Do you want to quit or return to menu?") option = (input("y or n\n")) if option == "y": @@ -141,7 +141,7 @@ def menu(): elif output == "2": with open('output.txt', 'a') as output_file: output_file.write('\n') - print(groups, file=output_file) + print(gid, file=output_file) exit() elif option == "2":