Ancora pascal...
dunque...di solito il pascal (o almeno per come lo so usare io) è un programma autonomo...mi spiego...quando metto in esecuzione il programma non interagisce col "mondo esterno" ma legge unicamente ciò che gli viene ordinato sul listato...
ora io ho la necessità di interagire con internet tramite Pascal..
il mio problema è questo..
mettiamo che io debba trovare una pagina così scritta:
www.vecchio123.it
ma che non sappia il numero associato al nome (123)...visto che non posso passare mezza giornata davanti ad IE per provare tutti i numeri consecutivi
www.vecchio1.it
www.vecchio2.it
...
www.vecchio123.it
avevo pensato di realizzare un programma che incrementasse da se' il numero dopo il nome e che si fermasse quando ricevesse da internet segnale positivo...è chiaro il mio problema? è possibile fare qualcosa del genere?
fatemi sapere
saluti
il vecchio
P.S.
se avete altre soluzioni che esulano dal Pascal sono bene accette cmq... [;)]
ora io ho la necessità di interagire con internet tramite Pascal..
il mio problema è questo..
mettiamo che io debba trovare una pagina così scritta:
www.vecchio123.it
ma che non sappia il numero associato al nome (123)...visto che non posso passare mezza giornata davanti ad IE per provare tutti i numeri consecutivi
www.vecchio1.it
www.vecchio2.it
...
www.vecchio123.it
avevo pensato di realizzare un programma che incrementasse da se' il numero dopo il nome e che si fermasse quando ricevesse da internet segnale positivo...è chiaro il mio problema? è possibile fare qualcosa del genere?
fatemi sapere
saluti
il vecchio
P.S.
se avete altre soluzioni che esulano dal Pascal sono bene accette cmq... [;)]

Risposte
con il c si puo' fare una cosa del genere se ti interessa dimmelo che domani ti rispondo, ora proprio non ho la forza per farlo (guarda che ore sono mentre ti scrivo:)
comunque quello che ti interessa sono i socket per la programmazione di rete e qualche funzione della libreria string.h
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
comunque quello che ti interessa sono i socket per la programmazione di rete e qualche funzione della libreria string.h
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
ok vai spiega pure...e casomai credo proprio che dovrai:
1) dirmi dove posso scaricare il C
2) consigliarmi un buon manuale on line
3) in caso non fossi capace scrivermi il listato del programma, del quale poi modificherò alcune cose in modo da poter crercare il sitoo che mi interessa
ti ringrazio anticipatamente
saluti
il vecchio
1) dirmi dove posso scaricare il C
2) consigliarmi un buon manuale on line
3) in caso non fossi capace scrivermi il listato del programma, del quale poi modificherò alcune cose in modo da poter crercare il sitoo che mi interessa
ti ringrazio anticipatamente
saluti
il vecchio

per linux:
#gcc prog.c -o prog
ti compila il file prog.c in prog
per windows il compilatore e' devcpp, per scaricarlo: http://www.bloodshed.net/devcpp.html (scarica la 4)
i file devono essere *.c
una guida generale al c la puoi trovare a: http://ada2.unipv.it/biblio/trickyc/00c.htm (oppure scaricati la versione in pdf, il titolo e' "tricky c")
qualche manuale sull' uso dei socket:
http://www.mojodo.it/index.php?pg=lessons
http://www.valtellinux.it/prj/rete/
ma probabilmente la migliore e'
http://www.ecst.csuchico.edu/~beej/guide/net/
se hai qualche problema dimmelo
per trasformare la stringa comunque le funzioni che ti servono sono:
strcpy(string, "ciao"); //mette la stringa "ciao" (senza virgolette) nella variabile string
strcat(string1, string2); //concatena string2 a string1
puoi fare una cosa del genere
char string1[40], string2[40]; //due variabili che possono contenere massimo 40 caratteri
strcpy(string1, "www.vecchio"); //ora string 1 contiene "www.vecchio" (senza virgolette)
//qui ti crei le seconda parte dell' indirizzo e la metti in string2
//mettiamo che per esempio la seconda parte ora sia "123.it"
strcat(string1, string2); //ora string1 contiene "www.vecchio123.it"
//qui provi a collegarti all' indirizzo contenuto in string1 attraverso i socket
//se si collega il programma termina, altrimenti cambi indirizzo
ovviamente ti serve un ciclo che ogni volta ti modifica l' indirizzo e prova a collegarsi
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
#gcc prog.c -o prog
ti compila il file prog.c in prog
per windows il compilatore e' devcpp, per scaricarlo: http://www.bloodshed.net/devcpp.html (scarica la 4)
i file devono essere *.c
una guida generale al c la puoi trovare a: http://ada2.unipv.it/biblio/trickyc/00c.htm (oppure scaricati la versione in pdf, il titolo e' "tricky c")
qualche manuale sull' uso dei socket:
http://www.mojodo.it/index.php?pg=lessons
http://www.valtellinux.it/prj/rete/
ma probabilmente la migliore e'
http://www.ecst.csuchico.edu/~beej/guide/net/
se hai qualche problema dimmelo
per trasformare la stringa comunque le funzioni che ti servono sono:
strcpy(string, "ciao"); //mette la stringa "ciao" (senza virgolette) nella variabile string
strcat(string1, string2); //concatena string2 a string1
puoi fare una cosa del genere
char string1[40], string2[40]; //due variabili che possono contenere massimo 40 caratteri
strcpy(string1, "www.vecchio"); //ora string 1 contiene "www.vecchio" (senza virgolette)
//qui ti crei le seconda parte dell' indirizzo e la metti in string2
//mettiamo che per esempio la seconda parte ora sia "123.it"
strcat(string1, string2); //ora string1 contiene "www.vecchio123.it"
//qui provi a collegarti all' indirizzo contenuto in string1 attraverso i socket
//se si collega il programma termina, altrimenti cambi indirizzo
ovviamente ti serve un ciclo che ogni volta ti modifica l' indirizzo e prova a collegarsi
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
- edit
un modo molto piu' facile e': sprintf( msg, "%i", n);
ti mette nella variabile char msg il valore presente nella variabile int n
- edit
per convertire un int in un char ho trovato questo (spero che l' autore non me ne voglia se ho riportato questa spiegazione qui):
I believe that you will need to convert numbers highers then 10, so you will need not just a char, but a char string. To make just one char, here it is....
int value = 5;
char score = (char) value + 48;
(char) between () ensure that the value will be readed as a char...
48 is the ASCII code for the caracter 0...
Now, to convert an int number that is bigger than 10, you need a string... so... Lets create one routine to do that...
#define StrLength 10
int ConvertIntString(char* str, int value)
{
int i=0;
while(value > 0)
{ str = (char)(value % 10) + 48;
value = value / 10; i++;
}
return i;
}
int main()
{
char* str = new char[StrLength];
int length = ConvertIntString(str,76587654);
for(int i=length-1;i>=0;i--) cout<; // you can use your output function here to output the chars
delete str;
return 0;
}
well, i tested the above routines, and it works fine.... the ConvertIntString() returns in str pointer the int value converted to chars, but in backwards ( just to avoid computer process.) When you print it, you do it in backwards so you have the right direction of numbers again. Its important to have
a char* pointer and create a array of chars on it, so you can send it as parameter to the function. I dont know if there is any other lighter way to do it, avoind unnecessary computer process...
I hope it helps!!! Bye!!!!!
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
un modo molto piu' facile e': sprintf( msg, "%i", n);
ti mette nella variabile char msg il valore presente nella variabile int n
- edit
per convertire un int in un char ho trovato questo (spero che l' autore non me ne voglia se ho riportato questa spiegazione qui):
I believe that you will need to convert numbers highers then 10, so you will need not just a char, but a char string. To make just one char, here it is....
int value = 5;
char score = (char) value + 48;
(char) between () ensure that the value will be readed as a char...
48 is the ASCII code for the caracter 0...
Now, to convert an int number that is bigger than 10, you need a string... so... Lets create one routine to do that...
#define StrLength 10
int ConvertIntString(char* str, int value)
{
int i=0;
while(value > 0)
{ str = (char)(value % 10) + 48;
value = value / 10; i++;
}
return i;
}
int main()
{
char* str = new char[StrLength];
int length = ConvertIntString(str,76587654);
for(int i=length-1;i>=0;i--) cout<
delete str;
return 0;
}
well, i tested the above routines, and it works fine.... the ConvertIntString() returns in str pointer the int value converted to chars, but in backwards ( just to avoid computer process.) When you print it, you do it in backwards so you have the right direction of numbers again. Its important to have
a char* pointer and create a array of chars on it, so you can send it as parameter to the function. I dont know if there is any other lighter way to do it, avoind unnecessary computer process...
I hope it helps!!! Bye!!!!!
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
ho fatto prima a farti il programma =) (domani lo finisco)
se vuoi finirlo da solo leggiti tricky c per qualche conoscenza sul c (generale)
poi ho trovato questa guida perfetta per i nostri scopi sui socket, lascia perdere quelle che ti ho dato in precedenza: http://www.bsrf.org.uk/tutorials/csocketit.txt
//programma
#include
int main(){
char string1[30], string2[10];
int n=0, c=0;
while(n<1000){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//qui provi a connetterti al sito
//se ti connetti allora setti c=1 ed esci
//altrimenti passi all' iterazione successiva
//te lo faccio domani
}
if(!c) printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
se vuoi finirlo da solo leggiti tricky c per qualche conoscenza sul c (generale)
poi ho trovato questa guida perfetta per i nostri scopi sui socket, lascia perdere quelle che ti ho dato in precedenza: http://www.bsrf.org.uk/tutorials/csocketit.txt
//programma
#include
int main(){
char string1[30], string2[10];
int n=0, c=0;
while(n<1000){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//qui provi a connetterti al sito
//se ti connetti allora setti c=1 ed esci
//altrimenti passi all' iterazione successiva
//te lo faccio domani
}
if(!c) printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
ecco il programma completo se non dovesse funzionare qualcosa dimmelo
#include
#include
#include
#include
#include /* netbd.h è necessario per struct hostent */
#define PORT 80 /* porta aperta sull' host remoto */ //puoi cambiarla
int main(){
char string1[30], string2[10];
int n=0, c=0;
int fd; /* descrittori di file*/
struct hostent *he; /* struttura da cui si otterranno informazioni riguardo all'host remoto */
struct sockaddr_in server; /* informazioni sull'indirizzo del server */
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//codice rubato da una guida di BracaMan
if((he = gethostbyname(string1)) == NULL)
{ /* invoca gethostbyname() */
continue;//se non trova l' host passa direttamente all' iterazione successiva
}
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ /* invoca socket() */
continue;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT); /* si necessita ancora di htons() */
/*he->h_addr passa l'informazione di "*he" a "h_addr" */
server.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(server.sin_zero), 8);
if(connect(fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1)
{
continue;
}
//fine codice rubato da una guida di BracaMan
else {close(fd);c=1;break;}//se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
#include
#include
#include
#include
#include
#define PORT 80 /* porta aperta sull' host remoto */ //puoi cambiarla
int main(){
char string1[30], string2[10];
int n=0, c=0;
int fd; /* descrittori di file*/
struct hostent *he; /* struttura da cui si otterranno informazioni riguardo all'host remoto */
struct sockaddr_in server; /* informazioni sull'indirizzo del server */
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//codice rubato da una guida di BracaMan
if((he = gethostbyname(string1)) == NULL)
{ /* invoca gethostbyname() */
continue;//se non trova l' host passa direttamente all' iterazione successiva
}
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{ /* invoca socket() */
continue;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT); /* si necessita ancora di htons() */
/*he->h_addr passa l'informazione di "*he" a "h_addr" */
server.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(server.sin_zero), 8);
if(connect(fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1)
{
continue;
}
//fine codice rubato da una guida di BracaMan
else {close(fd);c=1;break;}//se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
perdonami ma sono un po' (parecchio) digiuno di C++...ho copiato il tuoo programma (non è che ci abbia capito moltissimo...però qualcosina si dai!! [;)])...ma quando lo compilo con Dev-C++ mi trova tre errori alla riga 3,4,5...credo, se ho ben capito, che non abbia
che a quanto ho capito (poco..) dovrebbero essere una specie di librerie dalle quali il programma attinge per poter funzionare..giusto?? dove le trovo allora?? ho provato a cercare su internet...ma non è che abbia capito molto...(mm...non è la prima volta che lo dico vero? [:D])
beh...fammi sapere..
ah..poi un altra cosa...il programma che ho scritto sul compilkatore lo devo salvare nella cartella in cui è installato il compilatore o posso anche salvarla sul desktop per esempio?
fammi sapere..non vedo l'ora di far girare questo programma!!!
che a quanto ho capito (poco..) dovrebbero essere una specie di librerie dalle quali il programma attinge per poter funzionare..giusto?? dove le trovo allora?? ho provato a cercare su internet...ma non è che abbia capito molto...(mm...non è la prima volta che lo dico vero? [:D])
beh...fammi sapere..
ah..poi un altra cosa...il programma che ho scritto sul compilkatore lo devo salvare nella cartella in cui è installato il compilatore o posso anche salvarla sul desktop per esempio?
fammi sapere..non vedo l'ora di far girare questo programma!!!

puoi anche salvarlo sul desktop =)
il problema e' che quelle librerie sono per linux =/
devi scaricarti una guida ai winsock (i socket per windows) e modificare il programma
oppure procurarti linux
p.s. finora ho trovato tutte guide ai winsock solo per visual basic
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
il problema e' che quelle librerie sono per linux =/
devi scaricarti una guida ai winsock (i socket per windows) e modificare il programma
oppure procurarti linux

p.s. finora ho trovato tutte guide ai winsock solo per visual basic
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
beh...adesso non è che mi metto a installare linux..anche perchè non lo saprei usare!!
per quanto riguarda i winsock...ti prego di aiutarmi a cercare perchè non mi è chiaro il tutto...
per quanto riguarda i winsock...ti prego di aiutarmi a cercare perchè non mi è chiaro il tutto...

senti io ho trovato questa pagina che credo possa essere inerente a quanto stiamo cercando...ma non so in che modo possa essere utile!!!!
cmq questo è il link...fammi sapere...
http://netgroup.polito.it/reti2/slide_v ... ckets.html
cmq questo è il link...fammi sapere...
http://netgroup.polito.it/reti2/slide_v ... ckets.html

se il problema è capire se esiste un sito a quell'indirizzo, ossia http://www.vecchioXXX.it allora puoi usare lo stesso protocollo HTTP con una richiesta di HEAD o GET (ma basterebbe HEAD)
In questo modo se la pagina di default di un sito (index.html o index.htm) esiste la risposta di HTTP sarà mi sembra 100 o 200 altrimenti 404 not found.
Se vuoi ho un piccolo e rudimentale programma java che invia una richiesta di GET a indirizzi che digiti su una text.
Dovresti modificarlo facendogli fare il loop su l'indirizzo www.vecchioXXX.it cambiando ad ogni giro il numero XXX e magari sostituendo alla stringa GET la HEAD così velocizzi il tutto.
ciao ciao
In questo modo se la pagina di default di un sito (index.html o index.htm) esiste la risposta di HTTP sarà mi sembra 100 o 200 altrimenti 404 not found.
Se vuoi ho un piccolo e rudimentale programma java che invia una richiesta di GET a indirizzi che digiti su una text.
Dovresti modificarlo facendogli fare il loop su l'indirizzo www.vecchioXXX.it cambiando ad ogni giro il numero XXX e magari sostituendo alla stringa GET la HEAD così velocizzi il tutto.
ciao ciao
emm...il problema è che io non so programmare in java...nè so cosa sia il protocollo http...quindi se puoi, dovresti mandarmi il programma già modificato...io provvederò a cambiare il nome del sito...questo non dovrebbe essere difficile...
grazie
ciao!
il vecchio
grazie
ciao!
il vecchio

si vecchio il link che hai trovato e' perfetto ti interessa soprattutto il programma
2.1.2 TCP Example - Winsock
p.s. ho potuto scriverti solo ora perche' sono tornato ieri dalla vacanza
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
2.1.2 TCP Example - Winsock
p.s. ho potuto scriverti solo ora perche' sono tornato ieri dalla vacanza
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
cioè? devo copiare un parte di quel programma? ma quale??

per ora l'unica miglioria che ho apportato (non so minimamente cosa ho fatto!!) è stata sostituire la scritta
#include
con
#include
tra l'altro andando a guardare nella cartella "include" del prohgramma ho visto che c'è anche un altro file chiamato "winsock2.h"..servirà? boh...
cmq una volta fatta questa modifica vado nuovamente a compilare il programma e stavolta non gli vanno bene i due include sottostanti, il netinet e il db...non ho proprio idea..
illuminami al più presto!!
ciao
il vecchio
#include
con
#include
tra l'altro andando a guardare nella cartella "include" del prohgramma ho visto che c'è anche un altro file chiamato "winsock2.h"..servirà? boh...
cmq una volta fatta questa modifica vado nuovamente a compilare il programma e stavolta non gli vanno bene i due include sottostanti, il netinet e il db...non ho proprio idea..
illuminami al più presto!!
ciao
il vecchio

prova questo spero che funzioni...
#include
#include
#define PORT 80
void client(char *);
int InitializeWinsock(WORD );
int main()
{
char string1[30], string2[10];
int n=0, c=0;
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//pero' forse devi convertire la stringa in ip non lo so come si fa mi dispiace
if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
if(!client(string1))continue;
else {WSACleanup();c=1;break;} //se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
int client(char * server_IP)
{
SOCKET fd; // "file" descriptor for the network socket
SOCKADDR_IN saddr;
char buf[MAX_STRING];
if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
printf("Errore durante la creazione del socket\n");
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(server_IP);
saddr.sin_port = htons(PORT);
// request connection to server socket (remote machine)
if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
return 0; //se non si connette ritorna 0
if (closesocket(fd) == SOCKET_ERROR)
printf("Errore durante la chiusura del socket\n");
return 1;
}
/**********************************************
* Windows Sockets Initialization *
**********************************************/
int InitializeWinsock(WORD wVersionRequested)
{
WSADATA wsaData;
int err;
err = WSAStartup(wVersionRequested, &wsaData);
// ritorna errore se, ad esempio, l'applicazione supporta al massimo
// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll
// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
// and in wVersion the minimum of its high version and wVersionRequested.
// wVersion is the The version of the Windows Sockets specification
// that the Windows Sockets DLL expects the caller to use.
// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora
// verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
// con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione
// vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi
// in questo caso
// Tell the user that we couldn't find a usable winsock.dll.
if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;
//Everything is fine: proceed
return 1;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
#include
#include
#define PORT 80
void client(char *);
int InitializeWinsock(WORD );
int main()
{
char string1[30], string2[10];
int n=0, c=0;
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//pero' forse devi convertire la stringa in ip non lo so come si fa mi dispiace
if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
if(!client(string1))continue;
else {WSACleanup();c=1;break;} //se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
int client(char * server_IP)
{
SOCKET fd; // "file" descriptor for the network socket
SOCKADDR_IN saddr;
char buf[MAX_STRING];
if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
printf("Errore durante la creazione del socket\n");
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(server_IP);
saddr.sin_port = htons(PORT);
// request connection to server socket (remote machine)
if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
return 0; //se non si connette ritorna 0
if (closesocket(fd) == SOCKET_ERROR)
printf("Errore durante la chiusura del socket\n");
return 1;
}
/**********************************************
* Windows Sockets Initialization *
**********************************************/
int InitializeWinsock(WORD wVersionRequested)
{
WSADATA wsaData;
int err;
err = WSAStartup(wVersionRequested, &wsaData);
// ritorna errore se, ad esempio, l'applicazione supporta al massimo
// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll
// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
// and in wVersion the minimum of its high version and wVersionRequested.
// wVersion is the The version of the Windows Sockets specification
// that the Windows Sockets DLL expects the caller to use.
// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora
// verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
// con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione
// vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi
// in questo caso
// Tell the user that we couldn't find a usable winsock.dll.
if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;
//Everything is fine: proceed
return 1;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
mmm..
stavolta mi segna 8 errori!!!
te li elenco:
26 c:\docume~1\..\forse.cpp void value not ignored as it ought to be
26 c:\docume~1\..\forse.cpp in argument to unary !
39 c:\docume~1\..\forse.cpp new declaration `int client(char *)'
7 c:\docume~1\..\forse.cpp ambiguates old declaration `void client(char *)'
42 c:\docume~1\..\forse.cpp `MAX_STRING' undeclared (first use this function)
42 c:\docume~1\..\forse.cpp (Each undeclared identifier is reported only once
42 c:\docume~1\..\forse.cpp for each function it appears in.)
42 | 'MA MA|
stavolta mi segna 8 errori!!!
te li elenco:
26 c:\docume~1\..\forse.cpp void value not ignored as it ought to be
26 c:\docume~1\..\forse.cpp in argument to unary !
39 c:\docume~1\..\forse.cpp new declaration `int client(char *)'
7 c:\docume~1\..\forse.cpp ambiguates old declaration `void client(char *)'
42 c:\docume~1\..\forse.cpp `MAX_STRING' undeclared (first use this function)
42 c:\docume~1\..\forse.cpp (Each undeclared identifier is reported only once
42 c:\docume~1\..\forse.cpp for each function it appears in.)
42 | 'MA MA|

Se vuoi per maggior chiarezza ti evidenzio le parti incriminate del file...
#include
#include
#define PORT 80
void client(char *);
int InitializeWinsock(WORD );
int main()
{
char string1[30], string2[10];
int n=0, c=0;
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//pero' forse devi convertire la stringa in ip non lo so come si fa mi dispiace
if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
if(!client(string1))continue;
else {WSACleanup();c=1;break;} //se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
int client(char * server_IP)
{
SOCKET fd; // "file" descriptor for the network socket
SOCKADDR_IN saddr;
char buf[MAX_STRING];
if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
printf("Errore durante la creazione del socket\n");
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(server_IP);
saddr.sin_port = htons(PORT);
// request connection to server socket (remote machine)
if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
return 0; //se non si connette ritorna 0
if (closesocket(fd) == SOCKET_ERROR)
printf("Errore durante la chiusura del socket\n");
return 1;
}
/**********************************************
* Windows Sockets Initialization *
**********************************************/
int InitializeWinsock(WORD wVersionRequested)
{
WSADATA wsaData;
int err;
err = WSAStartup(wVersionRequested, &wsaData);
// ritorna errore se, ad esempio, l'applicazione supporta al massimo
// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll
// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
// and in wVersion the minimum of its high version and wVersionRequested.
// wVersion is the The version of the Windows Sockets specification
// that the Windows Sockets DLL expects the caller to use.
// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora
// verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
// con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione
// vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi
// in questo caso
// Tell the user that we couldn't find a usable winsock.dll.
if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;
//Everything is fine: proceed
return 1;
}
#include
#include
#define PORT 80
void client(char *);
int InitializeWinsock(WORD );
int main()
{
char string1[30], string2[10];
int n=0, c=0;
for(n=0;n<1000;n++){ //i tentativi si effettuano fino a www.vecchio1000.it
strcpy(string1, "www.vecchio");
sprintf(string2, "%i", n);
strcat(string1, string2);
strcat(string1, ".it");
//pero' forse devi convertire la stringa in ip non lo so come si fa mi dispiace
if (!InitializeWinsock (MAKEWORD(1,1) ) ) return 1;
if(!client(string1))continue;
else {WSACleanup();c=1;break;} //se ti connetti metti c=1 ed esci da ciclo
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
int client(char * server_IP)
{
SOCKET fd; // "file" descriptor for the network socket
SOCKADDR_IN saddr;
char buf[MAX_STRING];
if ((fd=socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
printf("Errore durante la creazione del socket\n");
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = inet_addr(server_IP);
saddr.sin_port = htons(PORT);
// request connection to server socket (remote machine)
if (connect(fd, (LPSOCKADDR) &saddr, sizeof(saddr)) == SOCKET_ERROR)
return 0; //se non si connette ritorna 0
if (closesocket(fd) == SOCKET_ERROR)
printf("Errore durante la chiusura del socket\n");
return 1;
}
/**********************************************
* Windows Sockets Initialization *
**********************************************/
int InitializeWinsock(WORD wVersionRequested)
{
WSADATA wsaData;
int err;
err = WSAStartup(wVersionRequested, &wsaData);
// ritorna errore se, ad esempio, l'applicazione supporta al massimo
// la versione 1.1 e la DLL supporta da 2.0 in su (le versioni non si sovrappongono)
if (err!=0) return 0; // Tell the user that we couldn't find a usable winsock.dll
// WSAStartup returns in wHighVersion (struct wsaData) the highest version it supports
// and in wVersion the minimum of its high version and wVersionRequested.
// wVersion is the The version of the Windows Sockets specification
// that the Windows Sockets DLL expects the caller to use.
// Se WSAStartup ritorna un risultato accettabile, l'applicazione deve ancora
// verificare che il risultato sia compatibile con la sua richiesta. Ad esempio,
// con wVersionRequested=1.1 e DLL version 1.0, wVersion=1.0. Se l'applicazione
// vuole assolutamente usare la DLL 1.1, deve ancora verificare di non trovarsi
// in questo caso
// Tell the user that we couldn't find a usable winsock.dll.
if (LOBYTE(wsaData.wVersion )!=1 || HIBYTE(wsaData.wVersion)!=1) return 0;
//Everything is fine: proceed
return 1;
}

perdonami se ti creo tanti problemi...
grazie infinite per la mano che mi stai dando...
riguardo al primo programma che mi hai scritto, mi dicesti, se non erro, che girava tranquillamente su Linux...giusto?
beh...se proprio non riusciamo (riesci...) a farlo anche per windows io gfra qualche giorno torno in università..e là c'è linux...dici che potrò agire senza problemi? o anche lì dovrò aggiungere qualcosa? i sockets tipo sono già presenti nel pacchetto linux?
...perdonami ancora...
grazie
il vecchio
grazie infinite per la mano che mi stai dando...
riguardo al primo programma che mi hai scritto, mi dicesti, se non erro, che girava tranquillamente su Linux...giusto?
beh...se proprio non riusciamo (riesci...) a farlo anche per windows io gfra qualche giorno torno in università..e là c'è linux...dici che potrò agire senza problemi? o anche lì dovrò aggiungere qualcosa? i sockets tipo sono già presenti nel pacchetto linux?
...perdonami ancora...
grazie
il vecchio

per linux stai tranquillo... ho fatto anche una versione migliorata =) eccola:
#include
#include
#include
#include
#include
#define PORT 80
void usage(char *argv, int h){
if(h){
printf("Usage:\n%s <1° part of url> [starting number for 2° part of url] [ending number]\n", argv);
printf("Create strings www.arg1-number.arg2 (without \"-\") where number goes from arg3 to arg4\n");
printf("and tries to connect to each site. If there\'s no arg3 it is set to 0, and if there\'s no arg4\n");
printf("it is set to 1000.\n");
}
else printf("Try\n%s -h\n", argv);
exit(0);
}
int main(int argc, char *argv[]){
char string1[30], string2[10];
int start=0, c=0, end;
int fd;
struct hostent *he;
struct sockaddr_in server;
if(argc<2) usage(argv[0], 0);
if(!strcmp(argv[1], "-h")) usage(argv[0], 1);
if(argc<3) usage(argv[0], 0);
if(argv[3]) start=atoi(argv[3]);
else start=0;
if(argv[4]) end=atoi(argv[4]);
else end=1000;
for(;start<=end;start++){
strcpy(string1, "www.");
strcat(string1, argv[1]);
strcat(string1, ".");
if(argv[3]){
sprintf(string2, "%i", start);
strcat(string1, string2);
}
strcat(string1, argv[2]);
if((he = gethostbyname(string1)) == NULL){
continue;
}
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
continue;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(server.sin_zero), 8);
if(connect(fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1){
continue;
}
else {close(fd);c=1;break;}
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen
#include
#include
#include
#include
#include
#define PORT 80
void usage(char *argv, int h){
if(h){
printf("Usage:\n%s <1° part of url>
printf("Create strings www.arg1-number.arg2 (without \"-\") where number goes from arg3 to arg4\n");
printf("and tries to connect to each site. If there\'s no arg3 it is set to 0, and if there\'s no arg4\n");
printf("it is set to 1000.\n");
}
else printf("Try\n%s -h\n", argv);
exit(0);
}
int main(int argc, char *argv[]){
char string1[30], string2[10];
int start=0, c=0, end;
int fd;
struct hostent *he;
struct sockaddr_in server;
if(argc<2) usage(argv[0], 0);
if(!strcmp(argv[1], "-h")) usage(argv[0], 1);
if(argc<3) usage(argv[0], 0);
if(argv[3]) start=atoi(argv[3]);
else start=0;
if(argv[4]) end=atoi(argv[4]);
else end=1000;
for(;start<=end;start++){
strcpy(string1, "www.");
strcat(string1, argv[1]);
strcat(string1, ".");
if(argv[3]){
sprintf(string2, "%i", start);
strcat(string1, string2);
}
strcat(string1, argv[2]);
if((he = gethostbyname(string1)) == NULL){
continue;
}
if((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1){
continue;
}
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(server.sin_zero), 8);
if(connect(fd, (struct sockaddr *)&server, sizeof(struct sockaddr)) == -1){
continue;
}
else {close(fd);c=1;break;}
}
if(!c)printf("Non sono riuscito a collegarmi a nessun sito\n");
else printf("Mi sono collegato al sito %s\n", string1);
return 0;
}
-----------------------
Il bello di essere intelligente e' che puoi divertirti a fare l' imbecille, ma se sei un imbecille non puoi fare il contrario.
Woody Allen