C++,获取另一台电脑的ip地址
用一根网线把两台电脑连接起来,怎么获得另一台电脑的ip地址啊,用C++写个程序获取
[解决办法]
- C/C++ code
#include <windows.h>#include <stdio.h>char cmdstr[256];int i;int YN(int k) { FILE *f; char fn[40]; char ln[80]; int yn=0; sprintf(fn,"d:\\ping%d.txt",k); f=fopen(fn,"r"); if (NULL!=f) { fgets(ln,80,f); fgets(ln,80,f); fgets(ln,80,f); if (1==fscanf(f,"Re%c",&yn)) yn='q'-yn; fclose(f); unlink(fn); } return yn;}void main() { for (i=115;i<130;i++) { sprintf(cmdstr,"cmd /c ping 192.168.2.%d -n 1 -w 1000 >d:\\ping%d.txt",i,i); WinExec(cmdstr,SW_HIDE); } Sleep(3000); for (i=115;i<130;i++) { printf("%d 192.168.2.%d\n",YN(i),i); }}//1 192.168.2.115//0 192.168.2.116//0 192.168.2.117//0 192.168.2.118//1 192.168.2.119//0 192.168.2.120//0 192.168.2.121//0 192.168.2.122//1 192.168.2.123//0 192.168.2.124//0 192.168.2.125//1 192.168.2.126//0 192.168.2.127//1 192.168.2.128//0 192.168.2.129