recupérer l'adresse IP

LastikoLastiko Membre
23:31 modifié dans API UIKit #1
bonsoir ,

est ce que quelqu'un a deja fait ca sur l'iphone ?

Réponses

  • LastikoLastiko Membre
    23:31 modifié #2
    voila j'ai trouvé ce petit code qui récupére l'adresse IP de l'ipod

    http://www.appsamuck.com/day4.html

    -(NSString*)getAddress {<br />	char iphone_ip[255];<br />	strcpy(iphone_ip,&quot;127.0.0.1&quot;); // if everything fails<br />	NSHost* myhost =[NSHost currentHost];<br />	if (myhost)<br />	{<br />		NSString *ad = [myhost address];<br />		if (ad)<br />			strcpy(iphone_ip,[ad cStringUsingEncoding: NSISOLatin1StringEncoding]);<br />	}<br />	return [NSString stringWithFormat:@&quot;%s&quot;,iphone_ip]; <br />}<br /><br /> - (void)viewDidLoad {<br />	 NSString* address = [self getAddress];<br />	 NSString* myIPAdress = [NSString stringWithFormat:@&quot;IP Address: %@&quot;, address];<br />	 textView.text = myIPAdress;<br /> }
    


    ca recupere l'adresse ip sous la forme 192.168.0.24 ( par exemple )

    ce que je cherche a faire c'est récupérer chaque valeur pour les stocker
    par exemple
    Donnée 1 = 192
    Donnee 2 = 168
    etc

    une idée ?
  • 23:31 modifié #3
    <br />NSArray* IPParts = [myIPAddress componentsSeparatedByString:@&quot;.&quot;];<br /><br />NSString* donnee1 = [IPParts objectAtIndex:0];<br />NSString* donnee2 = [IPParts objectAtIndex:1];<br />....<br />
    
  • LastikoLastiko Membre
    23:31 modifié #4
    Hello Eaglelouk

    Merci je vais tester direct :P
  • LastikoLastiko Membre
    23:31 modifié #5
    Eagle

    encore merci ca marche nikel
Connectez-vous ou Inscrivez-vous pour répondre.