C语言实现连接Samba服务器的小工具



实验目的

接上篇文章 Samba服务的简单搭建,简化连接和清除缓存功能,实现偷懒



实验环境

  • vs2013
  • win10


实验展示

运行程序
1


查看连接列表
在这里插入图片描述


删除连接(单个)
3



实验源码

#define _CRT_SECURE_NO_WARNINGS// 强行除去安全检查
#include <stdio.h>
#include <string.h>

void logo();
void getConnection();
void showConnection();
void delConnection();
void cleanAllConnection();


int main() 
{
	int num = 0;

	while (1)
	{
		logo();
		scanf("%d", &num);
		if (num == 0)
		{
			return;
		}
		else
		{
			switch (num)
			{

			case 1:
				getConnection();
				break;

			case 2:
				showConnection();
				break;

			case 3:
				delConnection();
				break;

			case 4:
				cleanAllConnection();
				break;

			default:
				printf("您输入的数据有误,请您重新输入!\n\n\n");
				break;
			}
		}	

		num = 0;
		

	}

	system("pause");
	return 0;
}


void logo()
{
	printf("smb服务器连接工具(v1.0)\n");
	printf("***************\n");
	printf("*   1.连接    *\n");
	printf("*   2.查看    *\n");
	printf("*   3.删除    *\n");
	printf("*   4.清空    *\n");
	printf("***************\n");
	printf("\n请输入选择(0:退出):");
}

// 连接
void getConnection()
{
	char cmd[81], IP[20];

	printf("请输入samba服务器的IP:");
	fflush(stdin);
	gets(IP);
	strcpy(cmd, "start \\\\");
	strcat(cmd, IP);
	system(cmd);
}

// 查看
void showConnection()
{
	system("net use");
}

// 删除单个连接
void delConnection()
{
	int i = 0;
	char cmd[81], path[81];
	printf("请输入要删除的samba服务器的连接(例:\\\\192.168.1.1\\public):");
	fflush(stdin);
	gets(path);
	strcpy(cmd, "net use ");
	strcat(cmd, path);
	strcat(cmd, " /del /y");
	system(cmd);
}

// 清空当前所有连接
void cleanAllConnection()
{
	char cmd[] = "net use * /del /y";
	system(cmd);
}


以上代码没有优化,还请各位大佬不喜勿喷

发布了10 篇原创文章 · 获赞 30 · 访问量 1391

猜你喜欢

转载自blog.csdn.net/qq_35502243/article/details/104175402