Run this Python script on your kali terminal to find IP address of specified interface.
#!/usr/bin/env python
import subprocess
import optparse
import re
# function to get interface from user as argument
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i","--interface", dest="interface", help="Interface to obtain router IP")
(options, arguments) = parser.parse_args()
if not options.interface:
parser.error("[-] Please specify interface, use --help for info. ")
return(options)
# function to read ip address from ifconfig with users specified interface
def get_ip(interface):
try:
ifconfig_result = subprocess.check_output(["ifconfig", interface])
ip_result = re.search(r"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4]\
[0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", str(ifconfig_result))
if ip_result:
return ip_result.group(0)
else:
print("[-] Can not read IP address.")
except subprocess.CalledProcessError as e:
return None
options = get_arguments()
ip_address = get_ip(options.interface)
print("Your IP address is " + str(ip_address))