How to scan all IPs and usernames in network neighbors

zhaozj2021-02-16  57

How to scan all IPs and usernames in network neighbors

#include "winsock2.h" #include "afxtempl.h" #include "winnetwk.h"

Join the lib link Project- "Setting-" LINK- "Object / Libary Modules Add to WS2_32.lib mpr.lib

Clist m_list; m_list.removeall ();

CSTRING STRTEMP; STRUCT HOSTENT * HOST; STRUCT IN_ADDR * PTR; / / Get IP Address

DWORD DWSCOPE = Resource_Context; NetResource * NetResource = NULL; Handle Henum; WnetopENENUM (DWScope, Null, Null, Null, & Henum);

WSADATA WSADATA; / / Start enumerating network resources WSAStartup (Makeword (1, 1), & WSADATA);

if (hEnum) // If the handle is valid {DWORD Count = 0xFFFFFFFF; DWORD BufferSize = 2048; LPVOID Buffer = new char [2048]; WNetEnumResource further enumeration call work WNetEnumResource (hEnum // Call WSAStartup, & Count, Buffer, & Buffersize); NetResource = (NetResource *) BUFFER;

Char szhostname [200];

for (unsigned int i = 0; i dwUsage == RESOURCEUSAGE_CONTAINER && NetResource-> dwType == RESOURCETYPE_ANY) {if (NetResource-> lpRemoteName) {CString strFullName = NetResource-> lpRemoteName; if (0 == strFullName.Left (2) .Compare ( "")) strFullName = strFullName.Right (strFullName.GetLength () - 2); // get the host name gethostname (szHostName, strlen (szhostname)); // Get the host information from the host name Host = gethostByname (strfullname); if (host == null) Continue; PTR = (struct in_addr *) Host-> h_addr_list [0]; ///// Extract IP address information, the address form is as follows: 211.40.35.76 INT A = PTR-> S_un.s_un_b.s_b1; // 211 int b = Ptr-> S_un.s_un_b.s_b2; // 40 int C = Ptr-> s_un. S_un_b.s_b3; // 35 INT D = PTR-> S_un.s_un_b.s_b4; // 76strtemp.format ("% s ->% d.% D.% D.% D", strfullname, A, B, C, d); // Add to the list m_list.addtail (strTemp);}}} delete buffer; // End enumeration work WnetCloseenum (henum);

// Uninstall Winsock.dll wsacleanup ();

List this machine IP address and name cstring m_stripaddress; wsadata wsadata; int ret = wsastartup (MakeWord (0x02, 0x02), & wsadata); if (IRET! = 0) {trace ("Initializing Winsock Dynamic Library error!"); M_StripAddress = ""; Return;

Struct in_addr localaddr; struct hostent * hp = null; char hostname [50]; gethostname (Hostname, 49); // host name

HP = gethostByname (hostname); // host information Memcpy (& localaddr, hp-> h_addr, hp-> h_length); // address

转载请注明原文地址:https://www.9cbs.com/read-20160.html

New Post(0)