您的位置:首页 > 理论基础 > 计算机网络

The only thing I can think of is to use something like "http://www.dyndns.org/cgi-bin/check_ip.cgi" others may have a be

2012-03-13 13:50 1131 查看
NSUInteger  an_Integer;
NSArray* ipItemsArray;
NSString*externalIP;

NSURL *iPURL =[NSURL URLWithString:@"http://www.dyndns.org/cgi-bin/check_ip.cgi"];

if(iPURL){
NSError*error = nil;
NSString*theIpHtml =[NSString stringWithContentsOfURL:iPURL
encoding:NSUTF8StringEncoding
error:&error];
if(!error){
NSScanner*theScanner;
NSString*text = nil;

theScanner =[NSScanner scannerWithString:theIpHtml];

while([theScanner isAtEnd]== NO){

// find start of tag
[theScanner scanUpToString:@"<" intoString:NULL];

// find end of tag
[theScanner scanUpToString:@">" intoString:&text];

// replace the found tag with a space
//(you can filter multi-spaces out later if you wish)
theIpHtml =[theIpHtml stringByReplacingOccurrencesOfString:
[NSString stringWithFormat:@"%@>", text]
withString:@" "];
ipItemsArray =[theIpHtml  componentsSeparatedByString:@" "];
an_Integer=[ipItemsArray indexOfObject:@"Address:"];

externalIP =[ipItemsArray objectAtIndex:  ++an_Integer];

}

NSLog(@"%@",externalIP);
}else{
NSLog(@"Oops... g %d, %@",
[error code],
[error localizedDescription]);
}
}

[pool drain];
return0;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐