[英]how to know the server IP address after opening a socket connection in iOS
I opened a socket connection.我打开了一个套接字连接。 I want to know server IP address
我想知道服务器 IP 地址
NSString *urlString = [NSString stringWithFormat:@"http://sample.com"];
NSURL *website = [NSURL URLWithString:urlString];
CFReadStreamRef readStream;
CFWriteStreamRef writeStream;
CFStreamCreatePairWithSocketToHost(NULL, ( CFStringRef)[website host], [portNo intValue], &readStream, &writeStream);
CFReadStreamSetProperty(readStream,kCFStreamNetworkServiceType,kCFStreamNetworkServiceTypeVoIP);
CFWriteStreamSetProperty(writeStream,kCFStreamNetworkServiceType,kCFStreamNetworkServiceTypeVoIP);
inputStream = ( NSInputStream *)readStream;
outputStream = ( NSOutputStream *)writeStream;
[inputStream open];
[outputStream open];
You can do a DNS lookup and get this info.您可以进行 DNS 查找并获取此信息。 A DNS lookup can be performed on any host name.
可以对任何主机名执行 DNS 查找。 See here: How to perform DNS query on iOS
请参阅此处: 如何在 iOS 上执行 DNS 查询
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.