程序调用shell设置ip地址
2013-04-19 09:24
274 查看
通过脚本设置ip地址和网关:
std::string setip = "ifconfig eth0 " +lineEdit_NetIp->text().toStdString() + " netmask " + lineEdit_NetMask->text().toStdString() + " && echo 1"; std::string setroute = "echo 1;route del default;route add default gw " + ui->lineEdit_NetGate->text().toStdString(); FILE *fp = popen(setip.c_str(), "r"); if (NULL == fp) { msgBox.setInformativeText(tr("The IP address is unusable!")); msgBox.exec(); return; } char getway[16] = {0}; if (NULL == fgets(getway, 16, fp)) { pclose(fp); msgBox.setInformativeText(tr("The IP address is unusable!")); msgBox.exec(); return; } if (getway[0] != '1') { msgBox.setInformativeText(tr("The IP address is unusable!")); msgBox.exec(); return; } pclose(fp); fp = NULL;
fp = popen(setroute.c_str(), "r"); if (NULL == fp) { msgBox.setInformativeText(tr("The route address is unusable!")); msgBox.exec(); exit(0); } char route[16] = {0}; if (NULL == fgets(route, 16, fp)) { pclose(fp); msgBox.setInformativeText(tr("The route address is unusable!")); msgBox.exec(); exit(0); } pclose(fp); if (route[1] != 0) { msgBox.setInformativeText(tr("The route address is unusable!")); msgBox.exec(); exit(0); }
相关文章推荐
- C程序调用shell脚本共有三种方法
- Google Chrome Protable 版设置为默认浏览器后,外部程序调用问题
- 在程序中调用ADO控件的ConnectionString设置框
- C程序调用shell脚本共有三种方法
- 程序中调用控制面板设置功能
- VB Shell调用后 等待程序运行结束
- android程序中调用shell命令
- 【原】Java程序调用远程Shell脚本
- 设置服务账号失败(WMI提供程序错误,对WMI提供程序的调用返回了错误代码:0x80074814)
- Linux(Ubuntu)下设置开机启动shell脚本执行Java程序jar包
- 使用shell脚本调用mysql数据库存储过程,并设置定时任务
- CMakeLists.txt中设置编译后的可执行程序优先调用本地库(和可执行程序在同一个文件夹下的库)
- 如何在java程序中调用linux命令或者shell脚本
- 在java程序中如何调用linux的命令?如何调用shell脚本呢?
- 设计一个Shell程序,在/userdata目录下建立50个目录,即user1~user50,并设置每个目录的权限为 rwxr-xr—
- SecureCRT图形界面(通过设置调用Xmanager - Passive程序)
- 如何在C程序中调用Shell 笔记
- Android shell 命令设置(获取)IP地址、网关、dns
- C程序调用shell脚本的三种方法
- 给文件右击菜单增加7-ZIP浏览功能(用注册表设置Shell调用预览命令)