how do i find my ipv4 using python?
Question: my server copy it if you want! :) how do i find my ipv4 using python? can i
you try to keep it real short?

    
    
    import socket
    
    def Main():
        host = '127.0.0.1'
        port = 5000
    
        s = socket.socket()
        s.bind((host,port))
    
        s.listen(1)
        c1, addr1 = s.accept()
        sending = "Connection:" + str(addr1)
        connection = (sending) 
        print(connection)
        s.listen(1)
        c2, addr2 = s.accept()
        sending = "Connection:" + str(addr2)
        connection = (sending)
        print(connection)
        while True:
            data1 = c1.recv(1024).decode('utf-8')
            data2 = c2.recv(1024).decode('utf-8')
            if not data1:                            
                break
            if not data2:
                break
            if data2:
                c1.send(data2.encode('utf-8'))
            if data1:
                c2.send(data1.encode('utf-8'))
        s.close() 
    
    if __name__== '__main__':
        Main() 
    

thx for the help i appreciate it!


Answer: That's all you need for the local address (returns a string):

    
    
    socket.gethostbyname(socket.gethostname())
    

