I created a request using a domain name, e.g.,
When you say "which the framework used" here, I assume you mean
WKWebView. Each of those is a slightly different situation, but in all of them, the answer is that it's not possible directly (but see below; it's possible indirectly). You have no access to the underlying sockets that any of them use. All of them use connection pooling, which complicates things slightly even if you could get "the socket." And in the case of
WKWebView, a single request to
www.google.com may generate several independent connections, each of which could potentially interact with a different IP address.
(I'm a bit fascinated about what you're trying to do. Due to load balancing, a single IP address doesn't mean a single server, so IP addresses are only marginally more identifying than CNAMEs. Mixing in reverse proxies....)
If you need this kind of access, you have to manage the socket yourself. That's generally possible with all of the systems except
WKWebView. I'll assume that you know already (or can easily study) how to create a socket and perform HTTP using
CFHTTPMessage. This is extensively covered in the CFNetwork Programming Guide. If you've created the socket, you can use
CFSocketCopyPeerAddress to check what host you really connected to. That's the piece you wanted.
Given you are able to create this kind of socket and manage it yourself, you can hook that into the major URL loaders (except
WKWebView) using an
NSURLProtocol. See Drop-in Offline Caching for UIWebView (and NSURLProtocol) for a quick introduction and some sample code. You just need to take the request and make it yourself with
CFSocket, giving you the chance to see the exact port you're connected to.