title: bind/connect to network interface card using python
body: <p>I am trying to connect/bind to a specific Network Interface Card (NIC) or wireless network interface. For instance, when I create a socket, I want to connect using the name of the network (such as 'wlan0' or 'eth0') instead of using the IP address.
  In JAVA I can do this easily with the following code:</p>
  
  <pre><code>//Initializing command socket
  
  //String networkCard = "wlan0"; //or could be "eth0", etc.
  
  NetworkInterface nif = NetworkInterface.getByName(networkCard);
  
  Enumeration&lt;InetAddress&gt; nifAddresses = nif.getInetAddresses();
  
  // IP address of robot connected to NIC       
  SocketAddress sockaddr = new InetSocketAddress("192.168.1.100", 80);
  
  sock = new Socket();
  
  // bind to the specific NIC card which is connected to a specific robot
  
  sock.bind(new InetSocketAddress(nifAddresses.nextElement(), 0));
  
  sock.connect(sockaddr,10000);
  </code></pre>
  
  <p>I want to translate this to Python, but I am having a hard time.
  Any suggestions on how to do this?</p>
  
  <p>I was using sockopt and the AF_CAN, but nothing is working.</p>
  
  <p>Thank you very much!!!</p>