目前,我有试图打开一个基于某些服务器上我与通信网页视图的AP。
不过,我允许用户在万一输入自己的服务器IP地址都在用iPhone / iPad和服务器(或其它设备)的能力是不一样的网络上。 不过,我尝试使用NSURLConnection的检测,如果我能打开与给定的IP然而NSURLConnection的永远不会返回一个错误的连接,即使服务器地址(甚至是随机的网址)完全是伪造的。
在.H
@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDataSource, UITableViewDelegate,UIWebViewDelegate, NSURLConnectionDataDelegate> {
在.M相关代码
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath
{
dev_ip = @"http://www.asdfasfdfa.com/";
//dev_ip = (random ip)
NSMutableURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:dev_ip]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
NSLog(@"Connection established");
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"No Device at designated IP"]
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
这个if / else语句总是输出“已建立连接。” 这是不是NSURLConnection的不应该被用来做什么? 如果是的话,我可以用,以检测在连接指定IP的设备。 我需要从尝试连接到恶意IP的有啥这样做的最佳方法停止用户?