Tom's Guide > Forum > Programmation > Wake On Lan, a me tester si possible!!!

Wake On Lan, a me tester si possible!!!

Forum Programmation : Wake On Lan, a me tester si possible!!!

TomsGuide.com : 800 000 inscrits répondent à toutes vos questions high-tech et informatique. Pour obtenir de l'aide, inscrivez-vous gratuitement !
Mot :    Pseudo :           
 

Ce programme permet de demarer les pc en réseaux.
Voici mon code programmé sous fedora core 3(linux ,ne fonctionne donc que sur linux) :
#include <sys/socket.h>
#include <sys/types.h>
#include <netdb.h>
#include <string.h>
#include <netinet/in.h>
#include <unistd.h>
#include <stdio.h>

unsigned char atox(char s)
{
if (s >= 'a'){
s -= 0x20;
}
if (s >= 'A'){
s -= 'A';
s += 10;
} else if ('1' <= s && s <= '9') {
s -= '1';
s += 1;
} else {
s = 0;
}
return((unsigned char)s);
}


int main(int argc,char* argv[])
{
system("clear" );
int socket_id;
struct sockaddr_in def_serveur;
int serveur_lg;
struct hostent *info_serveur;
int l=0;
int i,cpt;
int tampon;
unsigned char trame[20],mac[20]="001109279856",magique[105]={0xff,0xff,0xff,0xff,0xff,0xff},ip[16]="192.168.25.255";
printf("********************************* Wake on Lan *********************************\n\n" );
printf("\n Ce programme est totalement libre et utilisable sous Fedora uniquement\n\n" );
printf(" Developpe par Thomas.D et Raphael.F\n" );
do{
printf("\n\n ===>> Entrez votre adresse MAC\n ===>> " );
scanf("%s",mac);
}while(strlen(mac)!=12);


printf("\n ===>> Entrez l' IP\n ===>> " );
scanf("%s",ip);


for (i=0;i<strlen(mac);i++)
{ if ( ((int)(mac[i]) >=97) && ( (int)(mac[i])<=102) )
mac[i]=mac[i]-32;
}



l+=5;

mac[0] = atox(mac[0])*0x10 + atox(mac[1]);
mac[1] = atox(mac[2])*0x10 + atox(mac[3]);
mac[2] = atox(mac[4])*0x10 + atox(mac[5]);
mac[3] = atox(mac[6])*0x10 + atox(mac[7]);
mac[4] = atox(mac[8])*0x10 + atox(mac[9]);
mac[5] = atox(mac[10])*0x10 + atox(mac[11]);


for(cpt=6;cpt<102;cpt+=6)
{
magique[cpt]=mac[0];
magique[cpt+1]=mac[1];
magique[cpt+2]=mac[2];
magique[cpt+3]=mac[3];
magique[cpt+4]=mac[4];
magique[cpt+5]=mac[5];
magique[cpt+6]=mac[6];
l+=6;
}
printf("\n Trame magique hexa : " );

for(cpt=0;cpt<=l;cpt++)
printf("%02X ",magique[cpt]);

socket_id=socket(AF_INET,SOCK_DGRAM,0);


if(socket_id==-1)printf("\n ===>> erreur creation socket :-(\n" );
else printf("\n ===>> socket cree ;-)\n" );


def_serveur.sin_family=AF_INET;


info_serveur=gethostbyname(ip);


memcpy(&def_serveur.sin_addr,info_serveur->h_addr,info_serveur->h_length);
def_serveur.sin_port=htons(7);


serveur_lg=sizeof(struct sockaddr_in);


cpt=sendto(socket_id,magique,l+1,0,(struct sockaddr*)&def_serveur,serveur_lg);

// l+1 pour atteindre une longueur en bytes de 102 requise

if(cpt==-1)printf(" ===>> erreur envoi :-(\n" );
else printf(" ===>> paquet envoye ;-)\n" );
cpt=close(socket_id);//fermeture du socket
if(cpt==-1)printf(" ===>> erreur fermeture socket :-(\n" );

printf("\n Tapez entree pour clore ce programme\n" );
getchar();
getchar();
system("clear" );

return 0;
}

Merci de me dire si ce code fonctionne, car je n'est pas le matériel nécessaire. C'est très important, Merci.

Liens sponsorisés
Inscrivez-vous ou connectez-vous pour masquer ceci.

Personne ne peut m'aider!!!!!!!!!!!!!!!!!!!
svp......................

Répondre à raphy591
Tom's Guide > Forum > Programmation > Wake On Lan, a me tester si possible!!!
Aller à :

Il y a 242 utilisateurs connus et inconnus. Pour voir la liste des connectés connus, cliquez ici.

Attention

Vous allez répondre sur un sujet resté inactif pendant plus de 6 mois.
Assurez-vous d'apporter des éléments nouveaux à la discussion avant de poursuivre.

Répondre Annuler
Liens