获取arp -a 返回
const char * test = "接口: 192.168.1.144 --- 0x5"
" Internet 地址 物理地址 类型"
" 192.168.1.1 cc-81-da-02-ed-f1 动态"
" 192.168.1.255 ff-ff-ff-ff-ff-ff 静态"
" 224.0.0.22 01-00-5e-00-00-16 静态"
" 224.0.0.251 01-00-5e-00-00-fb 静态"
" 224.0.0.252 01-00-5e-00-00-fc 静态"
" 239.255.255.250 01-00-5e-7f-ff-fa 静态"
" 255.255.255.255 ff-ff-ff-ff-ff-ff 静态";
返回如上面的字符串,如何分割出来呢,获取mac 和 ip 地址的对应,有两种方法一是使用正则表达式,二是使用stl的stringstream 和getline 方法
1 使用stringstream1 分割行
2 分割字符串
3 插入map表
1.1、getline
使用getline 函数分割行,这个可以参考我的其他文章
1.2、使用streamstream 分割字符串 string test2 = " 192.168.1.1 cc-81-da-02-ed-f1 动态";
std::stringstream s(test2);
string s1, s2, s3;
s >> s1 >> s2 >> s3;
cout
关注
打赏