我DOWN过这程序
这个程序还包括发送电子邮件/FTP/PING/等等,吹是包括了所有网络编程方面的资料,而且界面挺COOL的,是E文版的,可惜现在找不着了

解决方案 »

  1.   

    void CNetSampleDlg::OnButton2() 
    {
    // TODO: Add your control notification handler code here // 鼠标置为运行状态
    CWaitCursor cur; // 清空列表
    m_ctrList.ResetContent();
    // 避免列表闪烁
    m_ctrList.SetRedraw(false);

    // 查询网络计算机名
    SearchNet(NULL,9);
    // 置列表为可见
    m_ctrList.SetRedraw(true);
    }BOOL CNetSampleDlg::SearchNet(LPNETRESOURCE lpNetRC_p, DWORD dwFlags_p)
    {
    #define _BIT(n) (1<<n)
    enum {
    GLOBALNET = _BIT(0), // search the entire network
    CONNECTED = _BIT(1), // search only currently connected resources
    REMEMBERED = _BIT(2), // search only "persistent" connections TYPE_ANY = _BIT(3), // search all types of resources
    TYPE_DISK = _BIT(4), // search all disk resources
    TYPE_PRINT = _BIT(5), // search all print resources SEARCHDEFAULT = _BIT(0) | _BIT(3)
    } ;
    #undef _BIT HANDLE hEnum=0;
    dwFlags_p=9;
    DWORD dwScope = RESOURCE_GLOBALNET ;
    if( dwFlags_p & CONNECTED ) dwScope = RESOURCE_CONNECTED ;
    else if( dwFlags_p & REMEMBERED ) dwScope = RESOURCE_REMEMBERED ;
    // else GLOBALNET ... DWORD dwType = RESOURCETYPE_ANY ;
    if( dwFlags_p & TYPE_DISK ) dwType = RESOURCETYPE_DISK ;
    else if( dwFlags_p & TYPE_PRINT ) dwType = RESOURCETYPE_PRINT ;
    // else TYPE_ANY ... DWORD dwResult = WNetOpenEnum(
    dwScope, // scope of enumeration
    dwType, // resource types to list
    0, // enumerate all resources
    lpNetRC_p, // pointer to resource structure (NULL at first time)
    &hEnum // handle to resource
    ) ;
    if (dwResult != NO_ERROR)
    MessageBox("Error"); DWORD dwBuffer = 16384 ; // 16K is reasonable size
    DWORD dwEntries = 0xFFFFFFFF ; // enumerate all possible entries
    LPNETRESOURCE lpnrLocal = 0; BOOL bRet = TRUE; try {
    do {
    // first allocate buffer for NETRESOURCE structures ...
    lpnrLocal = (LPNETRESOURCE) GlobalAlloc( GPTR, dwBuffer ) ; dwResult = WNetEnumResource(
    hEnum, // resource-handle
    &dwEntries,
    lpnrLocal,
    &dwBuffer
    ) ; if( dwResult == NO_ERROR ) {
    for( register DWORD i = 0 ; i < dwEntries ; i++ ) 
    {
    // if( ! OnHitResource( lpnrLocal[i] ) ) 
    // {
    // TRACE0("CNetwork::Enumerate(): OnHitResource() breaks enumeration\n");
    // throw CNetworkBreak(FALSE) ;
    // }
    NETRESOURCE &rNetRC=lpnrLocal[i];
    CString str;
    if ( rNetRC.dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
    {
    str = rNetRC.lpRemoteName;
    register int i=0;
    for ( ; str[i] == '\\'; ++i) ;
    if ( i )
    {
    str = str.Mid(i);
    str.MakeUpper();
    m_ctrList.AddString(str);
    }
    } if( RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage & RESOURCEUSAGE_CONTAINER) && lpnrLocal[i].dwDisplayType != RESOURCEDISPLAYTYPE_SERVER ) 
    if( !SearchNet( &lpnrLocal[i], dwFlags_p ) ) 
    {
    TRACE0( "CNetwork::Enumerate(): recursiv call failed\n" );
    // throw CNetworkBreak(FALSE);

    }
    // m_ctrList.AddString(str);

    else if( dwResult != ERROR_NO_MORE_ITEMS ) 
    {
    // throw CNetworkError(NetError(dwResult, TEXT("WNetEnumResource")));
    }
    } while( dwResult != ERROR_NO_MORE_ITEMS );

    // catch( ERROR err ) {
    // bRet = err.m_bRet;
    // }
    catch( DWORD A)
    {
    }
    if( lpnrLocal )
    GlobalFree((HGLOBAL) lpnrLocal);

    WNetCloseEnum(hEnum) ; return bRet;
    }
    P.S. 
    找到告诉我
      

  2.   

    sinet_emperor(皇帝) :能共享一下你的方法吗?
      

  3.   

    我试图显示IP和用户名字,但不能显示IP
      

  4.   

    命令行程序 "net view",显示本组中的所有计算机名字。
    另外用ADSI也可以
      

  5.   

    net view
    只能列出计算机名字,不能列出计算机IP
    而且只能列出本组计算机名
    我需要的是列出本网段的所有计算机和IP
      

  6.   

    step 1: this step contains all the modifications (done in netsearch.h include file). template <class t>
    class cnetsearch : public cnetwork {
        typedef bool (t::*nsfnc)(cnetsearch*, netresource &, dword);
        t *m_ptheobject;
        nsfnc m_nsfnc;
        dword data;
        public:
            cnetsearch() : m_ptheobject(0), m_nsfnc(0) {}
            void create(t * pobj, nsfnc fnc, dword data) {
                assert(pobj != 0);
                assert(fnc != 0);
                m_ptheobject = pobj;
                m_nsfnc = fnc;
                data = data;
            }
        protected: // overridables
            virtual bool onhitresource(netresource & rnetrc) {
                return (m_ptheobject->*m_nsfnc)(this,rnetrc,data);
            }
        virtual bool neterror(dword dwerrorcode, lpctstr lpszfunction) {
            switch(dwerrorcode) {
                case error_bad_netpath:
                case error_no_network:
                    // minor errors: continue enumeration
                    return true;
            }
            // serious error: break enumeration
            return cnetwork::neterror(dwerrorcode, lpszfunction);
        }
    };
    that's all. step 2: to use this class now, all you have to do (let's assume that you are doing it locally from a function) is following: 
      // update argument is false on initial serch and true when updating
    void cmydocument::scannetworkmachines(bool update)
    {
        cnetsearch<cmydocument> netwalker;
        netwalker.create(this,onnetresourcehit,(dword)update);
        netwalker.enumerate();
    }
    bool cmydocument::onnetresourcehit(cnetsearch<cmydocument> *net, netresource& res, dword data)
    {
        int ndx;
        if (net->isserver(res)) {
            cstring str = net->getremotename(res);
            for (int ndx = 0; str[ndx] == '\\' ; ++ndx) ;
            if (ndx)
                str = str.mid(ndx);
            str.makeupper();
            if (data == 0) {
                // this is an initial scan !!!
                // for example, create tcomputer object and add it to the list
            } else if (data == 1) {
                // this is an update !!!
                // for example, search for a tcomputer object in a list and if not found,
                // create a new one and add it to the list.
            }
        }
        return true;    // continue enumeration 
    }
      
      

  7.   

    hit an error at "class cnetsearch : public cnetwork "
      

  8.   

    You can use this code to retrieve the host information in a network and also get the IP address of each pc. Its something similar to what you see in the Network Neighbourhood list. All luck.1) Include winsock2.h2) In the Menu, go to Project-->Settings and in the Link tab, you can see a text box named Object/Library Modules. In that, add ws2_32.lib mpr.lib to the existing entries there. Those 2 libraries have to be added for this code snippet to compile without any linker errors.CString strTemp;
    struct hostent *host;
    struct in_addr *ptr; // To retrieve the IP AddressDWORD dwScope = RESOURCE_CONTEXT;
    NETRESOURCE *NetResource = NULL;
    HANDLE hEnum;
    WNetOpenEnum( dwScope, NULL, NULL, NULL, &hEnum );WSADATA wsaData;
    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];  for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); 
                                              i++, NetResource++ )
      {
        if ( NetResource->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);
             gethostname( szHostName, strlen( szHostName ) );
             host = gethostbyname(strFullName);
             if(host == NULL) continue; 
             ptr = (struct in_addr *) host->h_addr_list[0];         // Eg. 211.40.35.76 split up like this.
             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;  // 76         strTemp.Format("%s -->  %d.%d.%d.%d",strFullName,a,b,c,d);
             AfxMessageBox(strTemp);
          }
        }
      }
      delete Buffer;
      WNetCloseEnum( hEnum );
    }WSACleanup();// End of Code很简单的东西,不过只能获取windows的网络邻居的机器
      

  9.   

    http://vip.6to23.com/NowCan1/tech/netshare.htm
    http://nowcan.yeah.net
    这个也是局域网网上邻居的。
      

  10.   

    char szHostname[256];
      WSADATA wsaData;
      WORD wVersionRequested;
      if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
    {
    if (gethostname(szHostname, sizeof(szHostname)))
    {
    TRACE(_T("Failed in call to gethostname, WSAGetLastError returns %d\n"), WSAGetLastError());
    return FALSE;
    } //get host information from the host name
    HOSTENT* pHostEnt = gethostbyname(szHostname);
    if (pHostEnt == NULL)
    {
    TRACE(_T("Failed in call to gethostbyname, WSAGetLastError returns %d\n"), WSAGetLastError());
    return FALSE;
    } //check the length of the IP adress
    if (pHostEnt->h_length != 4)
    {
    TRACE(_T("IP address returned is not 32 bits !!\n"));
    return FALSE;
    } //call the virtual callback function in a loop
    int nAdapter = 0;
    BOOL bContinue = TRUE;
    while (pHostEnt->h_addr_list[nAdapter] && bContinue)
    {
    in_addr address;
    CopyMemory(&address.S_un.S_addr, pHostEnt->h_addr_list[nAdapter], pHostEnt->h_length);
    bContinue = EnumCallbackFunction(nAdapter, address);
    nAdapter++;
    }
     WSACleanup( );
    return TRUE;
      

  11.   

    http://vip.6to23.com/NowCan1/tech/netshare.htm
    显示不了IP
      

  12.   

    请问大虾,net view是怎么做的,为什么它可以那么快?
      

  13.   

    我刚上网的时候用过一个这种程序好像是叫netcat(网猫)
    它能显示任意一个IP范围内上网的计算机和用户名。
    有ping 和端口扫描功能。
      

  14.   

    procedure TNetworkBrowser.EnumerateNet(NetItems: TNetworkItems; lpnr:
    PNetResource);
    var
    dwResult, dwResultEnum: Integer;
    hEnum: THandle;
    cbBuffer, cEntries, i: Integer;
    nrArray: PNetResourceArray;
    NewItem: TNetworkItem;
    dwScope, dwType, dwUsage: Integer;
    begin
    cbBuffer := 16384;
    cEntries := $FFFFFFFF;case FScope of
    nsConnected: dwScope := RESOURCE_CONNECTED;
    nsGlobal: dwScope := RESOURCE_GLOBALNET;
    nsRemembered: dwScope := RESOURCE_REMEMBERED;
    nsContext: dwScope := RESOURCE_CONTEXT;
    else
    dwScope := RESOURCE_GLOBALNET;
    end;
    case FResourceType of
    nrAny: dwType := RESOURCETYPE_ANY;
    nrDisk: dwType := RESOURCETYPE_DISK;
    nrPrint: dwType := RESOURCETYPE_PRINT;
    else
    dwType := RESOURCETYPE_ANY;
    end;
    dwUsage := 0;
    if nuConnectable in FUsage then
    dwUsage := dwUsage or RESOURCEUSAGE_CONNECTABLE;
    if nuContainer in FUsage then
    dwUsage := dwUsage or RESOURCEUSAGE_CONTAINER;dwResult := WNetOpenEnum(dwScope, dwType, dwUsage, lpnr, hEnum);
    if dwResult <> NO_ERROR then Exit;GetMem(nrArray, cbBuffer);
    repeat
    dwResultEnum := WNetEnumResource(hEnum, cEntries, nrArray, cbBuffer);
    if dwResultEnum = NO_ERROR then
    for i := 0 to cEntries-1 do
    begin
    NewItem := TNetworkItem.Create;
    case nrArray[i].dwScope of
    RESOURCE_CONNECTED: NewItem.FScope := nsConnected;
    RESOURCE_GLOBALNET: NewItem.FScope := nsGlobal;
    RESOURCE_REMEMBERED: NewItem.FScope := nsRemembered;
    RESOURCE_CONTEXT: NewItem.FScope := nsContext;
    else
    NewItem.FScope := nsGlobal;
    end;
    case nrArray[i].dwType of
    RESOURCETYPE_ANY: NewItem.FResourceType := nrAny;
    RESOURCETYPE_DISK: NewItem.FResourceType := nrDisk;
    RESOURCETYPE_PRINT: NewItem.FResourceType := nrPrint;
    else
    NewItem.FResourceType := nrAny;
    end;
    case nrArray[i].dwDisplayType of
    RESOURCEDISPLAYTYPE_GENERIC: NewItem.FDisplay := ndGeneric;
    RESOURCEDISPLAYTYPE_DOMAIN: NewItem.FDisplay := ndDomain;
    RESOURCEDISPLAYTYPE_SERVER: NewItem.FDisplay := ndServer;
    RESOURCEDISPLAYTYPE_SHARE: NewItem.FDisplay := ndShare;
    RESOURCEDISPLAYTYPE_FILE: NewItem.FDisplay := ndFile;
    RESOURCEDISPLAYTYPE_GROUP: NewItem.FDisplay := ndGroup;
    RESOURCEDISPLAYTYPE_NETWORK: NewItem.FDisplay := ndNetwork;
    RESOURCEDISPLAYTYPE_ROOT: NewItem.FDisplay := ndRoot;
    RESOURCEDISPLAYTYPE_SHAREADMIN: NewItem.FDisplay :=
    ndShareAdmin;
      

  15.   

    RESOURCEDISPLAYTYPE_DIRECTORY: NewItem.FDisplay :=
    ndDirectory;
    RESOURCEDISPLAYTYPE_TREE: NewItem.FDisplay := ndTree;
    RESOURCEDISPLAYTYPE_NDSCONTAINER: NewItem.FDisplay :=
    ndNDSContainer;
    else
    NewItem.FDisplay := ndGeneric;
    end;
    NewItem.FUsage := [];
    if nrArray[i].dwUsage and RESOURCEUSAGE_CONNECTABLE <> 0 then
    Include(NewItem.FUsage, nuConnectable);
    if nrArray[i].dwUsage and RESOURCEUSAGE_CONTAINER <> 0 then
    Include(NewItem.FUsage, nuContainer);
    NewItem.FLocalName := StrPas(nrArray[i].lpLocalName);
    NewItem.FRemoteName := StrPas(nrArray[i].lpRemoteName);
    NewItem.FComment := StrPas(nrArray[i].lpComment);
    NewItem.FProvider := StrPas(nrArray[i].lpProvider);
    NetItems.Add(NewItem);
    // if container, call recursively
    if (nuContainer in NewItem.FUsage) and (FScope <> nsContext) then
    EnumerateNet(NewItem.FSubItems, @nrArray[i])
    end;
    until dwResultEnum = ERROR_NO_MORE_ITEMS;FreeMem(nrArray);
    WNetCloseEnum(hEnum);
    end;procedure TNetworkBrowser.Refresh;
    begin
    FItems.Clear;
    if FActive then
    EnumerateNet(FItems, nil);
    end;procedure TNetworkBrowser.SetActive(Value: Boolean);
    begin
    if Value <> FActive then
    begin
    FActive := Value;
    Refresh;
    end;
    end;procedure TNetworkBrowser.SetScope(Value: TNetScope);
    begin
    if Value <> FScope then
    begin
    FScope := Value;
    Refresh;
    end;
    end;procedure TNetworkBrowser.SetResourceType(Value: TNetResourceType);
    begin
    if Value <> FResourceType then
    begin
    FResourceType := Value;
    Refresh;
    end;
    end;procedure TNetworkBrowser.SetUsage(Value: TNetUsage);
    begin
    if Value <> FUsage then
    begin
    FUsage := Value;
    Refresh;
    end;
    end;procedure TNetworkBrowser.Open;
    begin
    Active := True;
    end;procedure TNetworkBrowser.Close;
    begin
    Active := False;
    end;end.