// net2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <winnetwk.h>
#include <tchar.h>
#include <lm.h>
int datetime(PTSTR server);
int fingerprint(PTSTR server);
int netbios(PTSTR server) ;
int users(PTSTR server) ;
int localgroup(PTSTR server) ;
int globalgroup(PTSTR server) ;
int session(PTSTR server) ;
int transport(PTSTR server) ;
void copyrite();
int _tmain(int argc, _TCHAR* argv[])
{
NETRESOURCE nr;
DWORD ret;
TCHAR username[100]=_T("");
TCHAR password[100]=_T("");
TCHAR ipc[100]=_T("");
system("cls.exe");
if(argc!=2)
{
printf("==您没有输入主机名,建议您重新执行本程序 ==\n");
return -1;
}
swprintf(ipc,_T("\\\\%s\\ipc$"),argv[1]);
nr.lpLocalName=NULL;
nr.lpProvider=NULL;
nr.dwType=RESOURCETYPE_ANY;
nr.lpRemoteName=ipc;
ret=WNetAddConnection2(&nr,username,password,0);
if(ret!=ERROR_SUCCESS)
{
_tprintf(_T("\nIPC$ 连接失败 .\n"));
return -1;
}
fingerprint(argv[1]);
netbios(argv[1]);
users(argv[1]);
localgroup(argv[1]);
globalgroup(argv[1]);
transport(argv[1]);
session(argv[1]);
ret=WNetCancelConnection2(ipc,0,TRUE);
if(ret!=ERROR_SUCCESS)
{
_tprintf(_T("IPC$ 解除连接失败.\n"));
return -1;
}
copyrite();
return 0;
}
int datetime(PTSTR server)
{
PTIME_OF_DAY_INFO pBuf=NULL;
NET_API_STATUS nStatus;
DWORD lerror;
_tprintf(_T("\n*** Date and Time ***\n"));
nStatus=NetRemoteTOD(server,(PBYTE*)&pBuf);
if(nStatus==NERR_Success)
{
if(pBuf!=NULL)
{
_tprintf(_T("\n当前日期:\t%.2d-%.2d-%d"),pBuf->tod_month,pBuf->tod_day,pBuf->tod_year);
_tprintf(_T("\n当前时间:\t%.2d:%.2d:%.2d.%.2d (GMT)"),pBuf->tod_hours,pBuf->tod_mins,pBuf->tod_secs,pBuf->tod_hunds);
pBuf->tod_hours=(pBuf->tod_hours+8)%24;
_tprintf(_T("\n当前时间:\t%.2d:%.2d:%.2d.%.2d (GMT+08:00)\n"),pBuf->tod_hours,pBuf->tod_mins,pBuf->tod_secs,pBuf->tod_hunds);
}
}
else
{
lerror=GetLastError();
if(lerror==997) //从msdn的System Error Codes中拷贝而来
{
_tprintf(_T("\nDateTime:\tOverlapped I/O operation is in progress. \n"));
}
else
{
_tprintf(_T("\nDatetime Error:\t%d\n"),lerror);
}
}
if(pBuf!=NULL)
{
NetApiBufferFree(pBuf);
}
return 0;
}
int fingerprint(PTSTR server) //求计算机指纹信息,以下代码参考msdn的sdk说明
{
DWORD dwlength;
DWORD dwLevel;
NET_API_STATUS nStatus;
PSERVER_INFO_101 pBuf;
DWORD lerror;
dwLevel=101;
pBuf=NULL;
dwlength=_tcslen(server);
_tprintf(_T("\n**** Fingerprint ****\n"));
nStatus=NetServerGetInfo((LPSTR)server,dwLevel,(PBYTE *)&pBuf);
if(nStatus==NERR_Success)
{
_tprintf(_T("\n计算机名:\t%s"),pBuf->sv101_name);
_tprintf(_T("\n计算机描述:\t%s"),pBuf->sv101_comment);
_tprintf(_T("\n平台:\t%d"),pBuf->sv101_platform_id);
_tprintf(_T("\n版本号:\t%d.%d"),pBuf->sv101_version_major,pBuf->sv101_version_minor);
_tprintf(_T("\nType:"));
if(pBuf->sv101_type & SV_TYPE_NOVELL)
{
_tprintf(_T("\t\tNovell server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_XENIX_SERVER)
{
_tprintf(_T("\t\tXenix server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DOMAIN_ENUM)
{
_tprintf(_T("\t\tPrimary domain .\n"));
}
if(pBuf->sv101_type & SV_TYPE_TERMINALSERVER)
{
_tprintf(_T("\t\tTerminal Server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_WINDOWS)
{
_tprintf(_T("\t\tWindows 95 or later.\n"));
}
if(pBuf->sv101_type & SV_TYPE_SERVER)
{
_tprintf(_T("\t\tA LAN Manager server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_WORKSTATION)
{
_tprintf(_T("\t\tA LAN Manager workstation.\n"));
}
if(pBuf->sv101_type & SV_TYPE_PRINTQ_SERVER)
{
_tprintf(_T("\t\tServer sharing print queue.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DOMAIN_CTRL)
{
_tprintf(_T("\t\tPrimary domain controller.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DOMAIN_BAKCTRL)
{
_tprintf(_T("\t\tBackup domain controller.\n"));
}
if(pBuf->sv101_type & SV_TYPE_AFP)
{
_tprintf(_T("\t\tApple File Protocol server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DOMAIN_MEMBER)
{
_tprintf(_T("\t\tLAN Manager 2.x domain member.\n"));
}
if(pBuf->sv101_type & SV_TYPE_LOCAL_LIST_ONLY)
{
_tprintf(_T("\t\tServers maintained by the browser.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DIALIN_SERVER)
{
_tprintf(_T("\t\tServer running dial-in service.\n"));
}
if(pBuf->sv101_type & SV_TYPE_TIME_SOURCE)
{
_tprintf(_T("\t\tServer running the Timesource service.\n"));
}
if(pBuf->sv101_type & SV_TYPE_SERVER_MFPN)
{
_tprintf(_T("\t\tMicrosoft File and Print for NetWare.\n"));
}
if(pBuf->sv101_type & SV_TYPE_NT)
{
_tprintf(_T("\t\tWindows NT/2000/XP workstation or server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_WFW)
{
_tprintf(_T("\t\tServer running Windows for Workgroups.\n"));
}
if(pBuf->sv101_type & SV_TYPE_POTENTIAL_BROWSER)
{
_tprintf(_T("\t\tServer that can run the browser service.\n"));
}
if(pBuf->sv101_type & SV_TYPE_BACKUP_BROWSER)
{
_tprintf(_T("\t\tServer running a browser service as backup.\n"));
}
if(pBuf->sv101_type & SV_TYPE_MASTER_BROWSER)
{
_tprintf(_T("\t\tServer running the master browser service.\n"));
}
if(pBuf->sv101_type & SV_TYPE_DOMAIN_MASTER)
{
_tprintf(_T("\t\tServer running the domain master browser.\n"));
}
if(pBuf->sv101_type & SV_TYPE_CLUSTER_NT)
{
_tprintf(_T("\t\tServer clusters available in the domain.\n"));
}
if(pBuf->sv101_type & SV_TYPE_SQLSERVER)
{
_tprintf(_T("\t\tAny server running with Microsoft SQL Server.\n"));
}
if(pBuf->sv101_type & SV_TYPE_SERVER_NT)
{
_tprintf(_T("\t\tWindows NT/2000 server that is not a domain controller.\n"));
}
}
else
{
lerror=GetLastError();
if(lerror==997)
{
_tprintf(_T("\nFingerprint:\tOverlapped I/O operation is in progress.\n"));
}
else
{
_tprintf(_T("\nFingerprint Error:\t%d\n"),lerror);
}
}
if(pBuf!=NULL)
{
NetApiBufferFree(pBuf);
}
return 0;
}
int netbios(PTSTR server)
{
DWORD er,tr,resume;
DWORD i,dwLength,dwLevel;
PSHARE_INFO_1 pBuf,pBuffer;
NET_API_STATUS nStatus;
DWORD lerror;
er=0;
tr=0;
resume=0;
dwLevel=1;
dwLength=_tcslen(server);
_tprintf(_T("\n****** Netbios ******\n"));
do
{
nStatus=NetShareEnum((LPSTR)server,dwLevel,(PBYTE *)&pBuf,MAX_PREFERRED_LENGTH,&er,&tr,&resume);
if((nStatus==ERROR_SUCCESS) || (nStatus==ERROR_MORE_DATA))
{