我尝试创建可以安装到Wi-Fi路由器的客户端应用程序(OpenWRT态度调整12.09)应用程序必须用C编写并实现OpenWRT守护进程方法。 当任何访客转向Wi-Fi并连接到我的SSID时,我需要在我的C程序中使用他的IP和MAC地址。 如何为我的C程序中的任何新连接用户(设计)获取IP和MAC地址? 我开始尝试对已经连接到路由器的任何IP使用arp命令:
#include #include #include int main() { char* ip = "192.168.1.101"; char output[255]; char command [255]; //system("arp -a"); sprintf(command,"%s %s %s","arp","-a",ip); FILE* arp = popen(command, "r" ); int i = 1; while (fgets(output, sizeof(output), arp) != 0) { i++; if ( i == 2 ) { printf("%s",output); char macAddress[18]; int index = (int)(strchr(output,'-')-output); printf( "n%d",index); printf ("n----%c", output[index-2]); memcpy(macAddress, &output[index-2], 17); macAddress[17] = ' '; printf("n%s",macAddress); } } pclose(arp); return 0; }
system("arp -a");
在Cross编译后,在Ubuntu中工作,但不适用于OpenWRT! 也许我需要选择其他方式?
提前感谢您的帮助
以上就是c/c++开发分享如何在连接的Wi-Fi用户的C程序中获取IP和MAC地址?相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/519415.html