从“inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0”提取出来“192.168.182.131”,写出C程序
时间: 2023-03-14 17:09:36 浏览: 131
下面的C程序可以提取出“192.168.182.131”:#include <stdio.h>
#include <string.h>int main()
{
char str[] = "inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0";
char ip[16]; char *p = strstr(str, ":");
if(p != NULL)
{
sscanf(p + 1, "%s", ip);
printf("ip=%s\n", ip);
} return 0;
}
相关问题
从“inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0”提取出来“192.168.182.131”,写出shell脚本
可以使用以下shell脚本提取出“192.168.182.131”:echo "inet addr:192.168.182.131 Bcast:192.168.182.255 Mask:255.255.255.0" | awk -F ":" '{print $2}' | awk '{print $1}'
linux下有eth0和wlan0如何手动设置路由: root@ZOWIEBOX:/# ifconfig eth0 Link encap:Ethernet HWaddr 00:58:7F:21:CF:01 inet addr:192.168.1.66 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2785 errors:1 dropped:16 overruns:0 frame:0 TX packets:4673 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:327352 (319.6 KiB) TX bytes:6556947 (6.2 MiB) Interrupt:14 wlan0 Link encap:Ethernet HWaddr B8:13:32:98:F7:4C inet addr:192.168.1.123 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2103 errors:0 dropped:21 overruns:0 frame:0 TX packets:2240 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:207880 (203.0 KiB) TX bytes:3088389 (2.9 MiB)
可以通过route命令手动设置路由。假设你要将eth0网卡的IP地址192.168.1.66的流量通过网关192.168.1.1发送出去,命令如下:
```
route add -net 0.0.0.0 gw 192.168.1.1 dev eth0
```
如果你要将wlan0网卡的IP地址192.168.1.123的流量通过网关192.168.1.1发送出去,命令如下:
```
route add -net 0.0.0.0 gw 192.168.1.1 dev wlan0
```
需要注意的是,这些路由设置只会在当前会话中生效。如果你希望永久保存这些设置,可以将它们添加到/etc/network/interfaces文件中。
阅读全文