├── README.md └── app.py /README.md: -------------------------------------------------------------------------------- 1 | # BasicPythonNetworkTool 2 | Cyber Security Course Term Project 3 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import socket 3 | import sys 4 | import subprocess 5 | import ipaddress 6 | import os 7 | import struct 8 | from tkinter import * 9 | 10 | def run(*args): 11 | val = entryIp.value 12 | print(val) 13 | def main(): 14 | try: 15 | while(1): 16 | print("""\n-----------------------------VOLKAN HACKER TOOLS----------------------------- 17 | || || 18 | || 1.Port Scanner || 19 | || 2.Ip Scanner || 20 | || 3.Send Ping || 21 | || 4.Packet Sniffer || 22 | || || 23 | -----------------------------------------------------------------------------""") 24 | print("Please Choose a Tool (1-4) :") 25 | chosen = input() 26 | 27 | if chosen == "1": 28 | portScanner() 29 | elif chosen == "2": 30 | ipScanner() 31 | elif chosen == "3": 32 | sendPing() 33 | elif chosen == "4": 34 | packetSniffer() 35 | else: 36 | print("Wrong Choise Try Again") 37 | 38 | except KeyboardInterrupt: 39 | sys.exit() 40 | 41 | def portScanner(): 42 | try: 43 | remoteServer = input("Enter a host to scan: ") 44 | remoteServerIP = socket.gethostbyname (remoteServer) 45 | 46 | print("-" * 60) 47 | print("Scanning...", remoteServerIP) 48 | print("-" * 60) 49 | 50 | for port in (20, 21, 22, 80, 443): 51 | print("port {} scanning ".format(port)) 52 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 53 | result = sock.connect_ex((remoteServerIP, port)) 54 | if result == 0: 55 | info = socket.getservbyport(port) 56 | print("Port {}. Open -- {}".format(port, info)) 57 | sock.close() 58 | 59 | except socket.gaierror: 60 | print('Hostname could not be resolved. Exiting') 61 | return 62 | 63 | except socket.error: 64 | print("Couldn't connect to server") 65 | return 66 | 67 | print('Scanning Completed.') 68 | return 69 | def ipScanner(): 70 | net_addr = input("Enter a network address in CIDR format(ex.192.168.1.0/24): ") 71 | ip_net = ipaddress.ip_network(net_addr) 72 | all_hosts = list(ip_net.hosts()) 73 | 74 | info = subprocess.STARTUPINFO() 75 | info.dwFlags |= subprocess.STARTF_USESHOWWINDOW 76 | info.wShowWindow = subprocess.SW_HIDE 77 | 78 | for i in range(len(all_hosts)): 79 | output = subprocess.Popen(['ping', '-n', '1', '-w', '500', str(all_hosts[i])], stdout=subprocess.PIPE, startupinfo=info).communicate()[0] 80 | 81 | if "Destination host unreachable" in output.decode('utf-8'): 82 | print(str(all_hosts[i]), "is Offline") 83 | elif "Request timed out" in output.decode('utf-8'): 84 | print(str(all_hosts[i]), "is Offline") 85 | else: 86 | print(str(all_hosts[i]), "is Online") 87 | return 88 | def sendPing(): 89 | ipaddr = input("Enter ip adress or hostname : ") 90 | command = "ping {}".format(ipaddr) 91 | print (os.system(command)) 92 | def packetSniffer(): 93 | s = socket.socket(socket.AF_INET,socket.SOCK_RAW,socket.IPPROTO_IP) 94 | s2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 95 | s2.connect(("8.8.8.8", 80)) 96 | s.bind((s2.getsockname()[0],0)) 97 | s.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL,1) 98 | s.ioctl(socket.SIO_RCVALL,socket.RCVALL_ON) 99 | while True: 100 | try: 101 | packet = s.recvfrom(65565) 102 | packet = packet[0] 103 | ip_header = packet[0:20] 104 | iph = struct.unpack('!BBHHHBBH4s4s', ip_header) 105 | version_ihl = iph[0] 106 | version = version_ihl >> 4 107 | ihl = version_ihl & 0xF 108 | iph_length = ihl * 4 109 | ttl = iph[5] 110 | protocol = iph[6] 111 | s_addr = socket.inet_ntoa(iph[8]) 112 | d_addr = socket.inet_ntoa(iph[9]) 113 | print ('Version : ' + str(version) + ' IP Header Length : ' + str(ihl) + ' TTL : ' + str(ttl) + ' Protocol : ' + str(protocol) + ' Source Address : ' + str(s_addr) + ' Destination Address : ' + str(d_addr)) 114 | tcp_header = packet[iph_length:iph_length+20] 115 | tcph = struct.unpack('!HHLLBBHHH', tcp_header) 116 | source_port = tcph[0] 117 | dest_port = tcph[1] 118 | sequence = tcph[2] 119 | acknowledgement = tcph[3] 120 | doff_reserved = tcph[4] 121 | tcph_length = doff_reserved >> 4 122 | print ('Source Port : ' + str(source_port) + ' Dest Port : ' + str(dest_port) + ' Sequence Number : ' + str(sequence) + ' Acknowledgement : ' + str(acknowledgement) + ' TCP header length : ' + str(tcph_length)) 123 | h_size = iph_length + tcph_length * 4 124 | data_size = len(packet) - h_size 125 | data = packet[h_size:] 126 | print (data) 127 | except KeyboardInterrupt: 128 | sys.exit() 129 | pass 130 | 131 | if __name__ == "__main__": 132 | main() 133 | --------------------------------------------------------------------------------