1. Use C programming to check whether the network card is connected to the network cable # Include <net/If. h> // iff_running
# Include <sys/IOCTL. h>
# Include <sys/socket. h>
# Include <netinet/in. h>
# Include <net/if_arp.h>
Int main ()
{
If (check_nic ("eth0") = 0)
Printf ("detect OK./N ");
Else
Printf ("detect fail./N ");
}
// If the network card is connected, 0 is returned; otherwise,-1 is returned.
Int check_nic (char * nic_name)
{
Struct ifreq IFR;
Int skfd = socket (af_inet, sock_dgram, 0 );
strcpy (IFR. ifr_name, nic_name);
If (IOCTL (skfd, siocgifflags, & IFR) <0)
{< br> return-1;
}< br> If (IFR. ifr_flags & iff_running)
return 0; // network cable inserted into the NIC
else return-1;
}< span style = "color: #000000; "> 2. Run the Linux Command to check whether the NIC is connected to the network root # ethtool eth0 reference: http://topic.csdn.net/u/20100920/16/7D58E76F-39FE-44B3-B4AC-D65D5AE57D2D.html