I am new to Python and having issues calling a variable from one func to use in another.
First function gets localhost IP, second function I would like to grab that IP and use it to port scan itself.
My open port function comes up with error 'AttributeError: 'function' object has no attribute 'ipv4''
Any help is greatly appreciated.
def get_IP():
ip = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip.connect(("8.8.8.8", 80))
print(ip.getsockname()[0])
ipv4 = ip.getsockname()[0]
ip.close()
return ipv4
def get_open_ports():
for port in range(1,65535):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)
result = s.connect_ex((get_IP.ipv4, port))
if result ==0:
print(f"Port {port} is open")
s.close()