根据网卡名获取IP地址,以及掩码地址
2023-09-14 08:59:45 时间
printf("%s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
printf("IP address of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
printf("Netmask of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
The socket used can be a TCP socket (SOCK_STREAM) as well.
If you also need the netmask then use the SIOCGIFNETMASK value in ioctl like this :
printf("IP address of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
printf("Netmask of %s - %s\n" , iface , inet_ntoa(( (struct sockaddr_in *) ifr.ifr_addr )- sin_addr) );
相关文章
- Moleft 专用函数库 (四) - 获取网址重定向之后地址
- Adobe Premiere CS6软件下载地址及安装教程-PR软件全版本下载地址
- Autocad 2023软件安装教程+安装包-cad软件全版本下载地址
- linux下通过python获得指定网卡的ip地址详解编程语言
- Linux系统下修改IP地址指南(修改ip地址linux)
- Linux 地址获取网关信息教程(linux获取网关)
- 网卡的硬件地址Linux中查看eth0网卡硬件地址的方法(linux查看eth0)
- Linux查看本机IP地址的实现方法(linux查看本机地址)
- 地址Linux 查看网卡硬件地址的技巧(linux 查看网卡硬件)
- ecshop订单确认中显示省市地址信息的方法
- 地址到经纬度坐标转化的JAVA代码
- C#实现获取MAC地址的方法