⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lkv.cpp

📁 读mac地址的程序
💻 CPP
字号:
#include"stdio.h"
#include"string.h"
#include"iostream.h"
#include"windows.h"
#include"winsock.h"
#include"wsipx.h"
#include"wsnwlink.h"
#pragma comment(lib,"ws2_32")
//#define MAX_PATH 256
/*
#define FILE_ATTRIBUTE_READONLY             0x00000001  
#define FILE_ATTRIBUTE_HIDDEN               0x00000002  
#define FILE_ATTRIBUTE_SYSTEM               0x00000004  
#define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
#define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
#define FILE_ATTRIBUTE_ENCRYPTED            0x00000040  
#define FILE_ATTRIBUTE_NORMAL               0x00000080  
#define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200  
#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
#define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
#define FILE_ATTRIBUTE_OFFLINE              0x00001000  
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000
typedef struct _WIN32_FIND_DATA {
    DWORD       dwFileAttributes;
    FILETIME    ftCreationTime;
    FILETIME    ftLastAccessTime;
    FILETIME    ftLastWriteTime;
    DWORD       nFileSizeHigh;
    DWORD       nFileSizeLow;
    DWORD       dwReserved0;
    DWORD       dwReserved1;
    CHAR        cFileName[ MAX_PATH ];
    CHAR        cAlternateFileName[ 16 ];
}
*/
int dealfile(char *files)
{
	printf("%s\n",files);
	return 1;
}
void findAllFile(char *pFilePath)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH+1];
DWORD dwError;

strncpy (DirSpec,pFilePath,strlen(pFilePath) + 1);
SetCurrentDirectory(pFilePath);
strncat (DirSpec, "\\*",3);
hFind = FindFirstFile(DirSpec, &FindFileData);

if(hFind==INVALID_HANDLE_VALUE){printf ("Invalid file handle. Error is %u\n", GetLastError());return;}
else
{
    if((FindFileData.dwFileAttributes&0x10)!=0x10)dealfile(FindFileData.cFileName);
    else if(strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
    {
		char Dir[MAX_PATH + 1];
	    strcpy(Dir, pFilePath);
        strncat(Dir, "\\", 2);
        strcat(Dir, FindFileData.cFileName);
        findAllFile(Dir);
	}

    while (FindNextFile(hFind,&FindFileData) != 0)
	{
        if((FindFileData.dwFileAttributes&0x10)!=0x10)dealfile(FindFileData.cFileName);
        else if(strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
		{
			char Dir[MAX_PATH + 1];
            strcpy(Dir,pFilePath);
            strncat(Dir,"\\", 2);
            strcat(Dir,FindFileData.cFileName);
            findAllFile(Dir);
		}
	}
	dwError = GetLastError();
	FindClose(hFind);
    if(dwError!=ERROR_NO_MORE_FILES){printf ("FindNextFile error. Error is %u\n", dwError);return;}
}
}
int disknum()
{
	int num=0;
    DWORD DiskInfo=GetLogicalDrives();
	while(DiskInfo)
	{
		if(DiskInfo&1)num++;
		DiskInfo>>=1;
	}
	printf("逻辑磁盘数量=%d\n",num);
	int DSLength=GetLogicalDriveStrings(0,NULL);
char* DStr = new char[DSLength];
GetLogicalDriveStrings(DSLength,(LPTSTR)DStr);
int DType;
int si=0;
BOOL fResult;
unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes;
for(int i=0;i<DSLength/4;++i)
{
	char dir[4]={DStr[si],':','\\','\0'};
	printf("%s  ",dir);
	DType = GetDriveType(DStr+i*4);
	if(DType == DRIVE_FIXED)printf("   硬盘   ");
	else if(DType == DRIVE_CDROM)printf("   光驱   ");
	else if(DType == DRIVE_REMOVABLE)printf(" 移动磁盘 ");
	else if(DType == DRIVE_REMOTE)printf(" 网络磁盘 ");
	else if(DType == DRIVE_RAMDISK)printf(" 虚拟磁盘 ");
	else if(DType == DRIVE_UNKNOWN)printf(" 未知设备 ");
	fResult=GetDiskFreeSpaceEx(dir,(PULARGE_INTEGER)&i64FreeBytesToCaller,(PULARGE_INTEGER)&i64TotalBytes,(PULARGE_INTEGER)&i64FreeBytes);
	if(fResult)
	{
		printf("totalspace=%d MB  ",i64TotalBytes/1024/1024);
		printf("freespace =%d MB\n",i64FreeBytesToCaller/1024/1024);
	}
	else printf("设备未准备好\n");
    si+=4;
}
	return 1;
}
int ipaddress()
{
   WORD wVersionRequested = MAKEWORD(1,1);//project->setting->link->objext/library modules加入ws2_32.lib
   WSADATA wsaData;                       //或者在头里加上#pragma comment(lib,"ws2_32")
   if (WSAStartup(wVersionRequested,&wsaData)){printf("WSAStartup failed %s\n", WSAGetLastError());return -1;}
   char hostname[256];
   int res = gethostname(hostname, sizeof(hostname));
   if (res!=0){printf("Error: %u\n", WSAGetLastError());return -1;}
   //printf("hostname=%s\n", hostname);
   hostent* pHostent = gethostbyname(hostname);
   if (pHostent==NULL) {printf("Error: %u\n", WSAGetLastError());return -1;}
   hostent& he = *pHostent;
   printf("主机名称=%s\n别名名称=%s\n地址类型=%d(2表示为internet)\n地址长度=%d字节\n",he.h_name, he.h_aliases, he.h_addrtype, he.h_length);
   sockaddr_in sa;
   for (int nAdapter=0; he.h_addr_list[nAdapter]; nAdapter++)
   {
	   memcpy(&sa.sin_addr.s_addr,he.h_addr_list[nAdapter],he.h_length);
       printf("网络地址: %s\n", inet_ntoa(sa.sin_addr));
   }
   WSACleanup();
   GetSystemMetrics
   return 0;
}     

int main()
{
	disknum();
	ipaddress();
    //findAllFile("d:\\");
	return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -