How to ping a sever from Swift test code

Hi,

We have a vpn service and to test the functionality of it, I am using UI test to connect and want to validate the working of vpn by pinging a private ip.

I am not able to figure out how to do it? Can you provide some suggestions.

FYI, sending a ping is only of limited usefulness because lots of environments block pings (yeah, that’s stupid, but there you go). The only way to know for sure whether you can connect to a service is to actually try that connection.

Having said that, it is possible to send pings on iOS. The technique shown by the SimplePing sample code works just fine on that platform.

That code is in Objective-C, not Swift. Using it from Swift should be easy. Converting it to Swift is a bit tricky because it uses BSD Sockets and BSD Sockets is notoriously hard to use from Swift. If you need this code to be in Swift, you should search the ’net to see if someone has already converted it (and then carefully audit their code because BSD Sockets is notoriously… well, you know the deal).

Oh, if ping (ICMP) is important to you, I encourage you to file an enhancement request against the Network framework for that feature. I doubt it’ll ever be a high priority, but it would be nice (-:

If you do file a bug, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How to ping a sever from Swift test code
 
 
Q