How do I make an outgoing socket to a SPECIFIC network interface?

前端 未结 3 2016
醉酒成梦
醉酒成梦 2020-12-08 07:35

I have a server with two different network interfaces, each with a different IP address. How can I create a socket so it\'ll go out a specific IP address?

I\'d prefe

3条回答
  •  一向
    一向 (楼主)
    2020-12-08 08:29

    import socket
    s = socket.socket()
    s.bind((get_ip_address('eth0'), 0))
    

    from Quora

提交回复
热议问题