Программу делал на своем компе под SUSE 10. Она основывается на ftplib 3.1
Запускаю ее - она послушно сканирует. После сканирования у меня в каталоге оказываются файлы названные как отсканированные сервера с листингом. Сырец скопировал на сервер. Скомпилировал, запустил - программа пробежала весь файл с ip адресами, подключившись нормально только к себе. На остальное сразу же выдала CONNECTION REFUSED. После ее работы оказались в папке те же файлы, но пустые. Только файл с листингом самого этого сервера был полным. На сервере стоит Red Hat EL 4 AS. У меня к нему root. 21 порт открыт - запускаю ftp - подключается ко всем. В чем может быть проблема?
Листинг
Код: Выделить всё
//azftp.c
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "ftplib.h"
/* exit values */
#define EX_SYNTAX 2 /* command syntax errors */
#define EX_NETDB 3 /* network database errors */
#define EX_CONNECT 4 /* network connect errors */
#define EX_LOGIN 5 /* remote login errors */
#define EX_REMCMD 6 /* remote command errors */
#define EX_SYSERR 7 /* system call errors */
static int logged_in = 0;
static char *host = NULL;
static char *user = NULL;
static char *pass = NULL;
static char mode = 'I';
static netbuf *conn = NULL;
void
ftp_connect(void){
if (conn) return;
if (host == NULL){
// fprintf(stderr,"Host name not specified\n");
// exit(EX_SYNTAX);
exit(0);
}
if (!logged_in){
if (user == NULL){
user = "anonymous";
if (pass == NULL) pass = "kolesnikov.vah@gmail.com";
}else if (pass == NULL) pass = "kolesnikov.vah@gmail.com";
if (!FtpConnect(host,&conn)){
// fprintf(stderr,"Unable to connect to host %s\n%s", host, ftplib_lastresp);
// exit(EX_CONNECT);
exit(0);
}
if (!FtpLogin(user,pass,conn)){
// fprintf(stderr,"Login failure\n%s",FtpLastResponse(conn));
// exit(EX_LOGIN);
exit(0);
}
logged_in = 1;
}
}
int
main(int argc, char *argv[])
{
printf("Let's start!\n");
char ipadr[15];
char daem[50];
int i,j;
int cnt=50;
FILE *ff;
ff=fopen(".ip2scan","r");
//-------------
while(!feof(ff))
{
printf("---->> New cycle begins ------------------------------>>\n");
for(i=0;i<cnt;i++)
{
if (fscanf(ff,"%s",ipadr))
{
// printf("Readed from file %s\n",ipadr);
if (fork()==0)
{
struct in_addr in;
struct hostent *hp;
if (inet_aton(ipadr,&in))
if(hp=gethostbyaddr((char*)&in.s_addr,sizeof(in.s_addr),AF_INET))
{
// printf(">> We get DNS name %s\t\t for %s\n",hp->h_name,ipadr);
if (fork()==0)
{
host=hp->h_name;
FtpInit();
ftp_connect();
if (conn)
{
sprintf(daem,"%s",hp->h_name);
FtpDir(daem,"-R",conn);
FtpClose(conn);
//start program
execl("addserver","adduser",hp->h_name,NULL);
}
exit(0);
}
wait();
}
else
{
// printf(">> Can't achieve DNS for %s\n",ipadr);
}
else {/**/}
exit(0);
}
else
{
//parent
}
}
else
{
//born and kill
if (fork()==0)
exit(0);
}
}
for(j=0;j<cnt;j++)
wait();
}
//-------------
/*for(j=0;j<6;j++)
{
if (j==5) j=168;
for(i=1;i<255;i++)
{
sprintf(ipadr,"%d.%d.%d.%d",192,168,j,i);
if (fork()==0)
{
struct in_addr in;
struct hostent *hp;
if( inet_aton( ipadr, &in ))
if(hp = gethostbyaddr((char*)&in.s_addr,sizeof(in.s_addr),AF_INET))
{
if (fork()==0)
{
host=hp->h_name;
printf("Try connect to %s\n",hp->h_name);
FtpInit();
ftp_connect();
if (conn)
{
sprintf(daem,"data/%s\n",hp->h_name);
FtpDir(daem,"-R",conn);
FtpClose(conn);
}
exit(0);
}
wait();
}
else
{}// printf( "gethostbyaddr error: %d on %s\n", h_errno,ipadr );
else
{}// printf( "inet_aton error\n" );
//-----------------
exit(0);
}
}
int kz;
for(kz=1;kz<255;kz++)
{wait();}
}*/
printf("Done\n");
return 0;
}