LAN's IP scan

xiaoxiao2021-03-06  15

#include #include // -------------------------------- ---------------------------------------- Bool getlanipaddress (tstrings * strings) {int OriginCount = strings-> count; struct hostent * host; struct in_addr * ptr; dword dwscope = resource_context; handle henum; netresource * netResource = null; Wsadata Wsadata; Int A, B, C, D;

WNetOpenEnum (dwScope, NULL, NULL, NULL, & hEnum); WSAStartup (MAKEWORD (1,1), & wsaData); if (hEnum) {DWORD Count = 0xFFFFFFFF; DWORD BufferSize = 2048; LPVOID Buffer = new char [2048]; WNetEnumResource (hEnum, & Count, Buffer, & BufferSize); netResource = (NETRESOURCE *) Buffer; char szHostName [200]; unsigned int i; for (i = 0; i dwusage == resourceUsage_container && netResource-> dwtype == resourcetype_any) {

if (netResource-> lpRemoteName) {String strFullName = netResource-> lpRemoteName; if (strFullName.Pos ( "") == 1) strFullName = strFullName.SubString (3, strFullName.Length () - 2);

Gethostname (SzhostName); Host = gethostByName (StrfullName.c_STR ());

IF (Host == NULL) Continue;

Ptr = (struct in_addr *) Host-> h_addr_list [0];

A = PTR-> S_un.s_un_b.s_b1; // 172 b = Ptr-> S_un.s_un_b.s_b2; // 22 c = Ptr-> S_un.s_un_b.s_b3; // 106 d = Ptr-> S_un.s_un_b .s_b4; //213strings->add (Format("%d.%D.%D.%D ", ORAYOFCONST ((a ,b ,c, sm))));}}

Delete buffer; wnetcloseenum (henum);

Washnup (); return (strings-> count> Origincount);} // --------------------------------- ------------------------------------------

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

New Post(0)