返回> 网站首页 

[转载]linux C下shell命令调用(设置IP地址)

yoours2012-11-10 14:03:34 阅读 1398

简介一边听听音乐,一边写写文章。

       函数原型:
                         int system(const char *string);
       如设置IP地址,语句为:
                         system("ifconfig eth0 172.23.2.225");

例如:
                        char ipaddress[60];
                        sprintf(ipaddress, "ifconfig eth0 %s", ipaddress);
                        system(ipaddress);
同理,可设置网关和子网掩码:
                       char netset[60];
                       sprintf(netset, "ifconfig eth0 netmask %s", netmask);
                       system(netset);
                       sprintf(netset, "ifconfig eth0 broadcast %s/0", bcast);
                       system(netset);
                        其中,netmask和bcast都是从软件盘输入得到的。
用一个语句设置IP、子网掩码、网关等:
                       sprintf(netset, “ifconfig eth0 %s netmask % broadcast %s”, ipaddress, netmask, bcast);
微信小程序扫码登陆

文章评论

1398人参与,0条评论