网上找的一个C++写的扫描局域网主机信息的程序,部分代码看不懂,求大神指导,非常感谢

karim_耿大少 2016-01-06 01:35:08
void CNeighborInfoDlg::ReceiveMessage()
{
BYTE Buf[500];
//m_UDPSocket.Receive(Buf,500,0);
static CString strOldIP;
CString str,strIP,strHost,strHex,strMac,Host,Group,User;
UINT dport;
m_socket.ReceiveFrom(Buf,500,strIP,dport,0);

if(strIP==(char)NULL||strIP==strOldIP)return;
strOldIP=strIP;

//ip
int index=m_ListView.InsertItem(0,strIP);

strHost="";
strHex="";
User="?";
Host="\\";

int tem=0,num=0;
bool bAdd=true;

for(int i=0;i<500;i++)
{
if(i%50==0)
TRACE("\n");
TRACE("%c",Buf[i]);
}

//nbtstat前面的57个字节是
for(i=57;i<500;i++) //57-72
{
//end
if(Buf[i]==0xcc)
break;

if(Buf[i]==0x20)
bAdd=false;
if(bAdd)
{
str.Format("%c",Buf[i]);
if(Buf[i]>=' ')strHost+=str;

str.Format("%02x.",Buf[i]);
strHex+=str;
}

if((++tem)%18==0)
{
bAdd=true;
//m_ListBox.AddString(strHost);//
strHost.TrimRight((char)NULL);
if(strHost=="")
{
strMac.Delete(17,strMac.GetLength()-17);
m_ListView.SetItem(index,4,LVIF_TEXT,strMac, 0, 0, 0,0);
break;
}

if(num==0&&strHost!="")
{
m_ListView.SetItem(index,2,LVIF_TEXT,strHost, 0, 0, 0,0);
Host=strHost;
num++;
}
else
{
if(Host!=strHost&&num==1&&strHost!="")
{
m_ListView.SetItem(index,1,LVIF_TEXT,strHost, 0, 0, 0,0);
Group=strHost;
num++;
}
else
{
if(strHost!=Host&&strHost!=Group&&num==2&&strHost!="")
{
User=strHost;
if(User!="__MSBROWSE__")
{
m_ListView.SetItem(index,3,LVIF_TEXT,User, 0, 0, 0,0);
num++;
}
}
}

}

strMac=strHex;
strHost="";
strHex="";

}

}

SetEvent(wait_handle);
}
...全文
270 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-01-07
  • 打赏
  • 举报
回复
C:\>nbtstat /? Displays protocol statistics and current TCP/IP connections using NBT (NetBIOS over TCP/IP). NBTSTAT [ [-a RemoteName] [-A IP address] [-c] [-n] [-r] [-R] [-RR] [-s] [-S] [interval] ] -a (adapter status) Lists the remote machine's name table given its name -A (Adapter status) Lists the remote machine's name table given its IP address. -c (cache) Lists NBT's cache of remote [machine] names and their IP addresses -n (names) Lists local NetBIOS names. -r (resolved) Lists names resolved by broadcast and via WINS -R (Reload) Purges and reloads the remote cache name table -S (Sessions) Lists sessions table with the destination IP addresses -s (sessions) Lists sessions table converting destination IP addresses to computer NETBIOS names. -RR (ReleaseRefresh) Sends Name Release packets to WINS and then, starts Refresh RemoteName Remote host machine name. IP address Dotted decimal representation of the IP address. interval Redisplays selected statistics, pausing interval seconds between each display. Press Ctrl+C to stop redisplaying statistics.
karim_耿大少 2016-01-06
  • 打赏
  • 举报
回复
主要是//nbtstat前面的57个字节是 下边的这些代码,能大概讲一下是干什么的,是什么意思就可以了,谢谢了
lilianjie001 2016-01-06
  • 打赏
  • 举报
回复
不会是每一行都给你注释出来吧

64,670

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧