简体   繁体   中英

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

    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. A DNS lookup can be performed on any host name. See here: How to perform DNS query on iOS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM