1

I want to ping the connected wifi network in iPhone using swift. I am able to get the SSID as

internal class SSID {
    class func fetchSSIDInfo() ->  String {
        var currentSSID = ""
        if let interfaces:CFArray = CNCopySupportedInterfaces() {
            for i in 0..<CFArrayGetCount(interfaces){
                let interfaceName: UnsafeRawPointer = CFArrayGetValueAtIndex(interfaces, i)
                let rec = unsafeBitCast(interfaceName, to: AnyObject.self)
                let unsafeInterfaceData = CNCopyCurrentNetworkInfo("\(rec)" as CFString)
                if unsafeInterfaceData != nil {

                    let interfaceData = unsafeInterfaceData! as Dictionary!
                    currentSSID = ((interfaceData as? [String : AnyObject])?["SSID"])! as! String

                }
            }
        }
        return currentSSID
    }
}
Uzair Dhada
  • 333
  • 2
  • 6
  • 23
  • What do you mean "ping the network"? Ping each host on the network? Ping the router? This is nothing to do with the ssid, you need the ip address – Paulw11 Dec 12 '16 at 11:10
  • lets say my iPhone is connected to a wifi network, So ill need ip address of that connected network. Now i want ping that network and get results of it like the iNetTools app in itunes. – Uzair Dhada Dec 12 '16 at 11:14
  • Do you mean you want to ping all of the hosts on that network? – Paulw11 Dec 12 '16 at 11:21
  • No i want to ping to the wifi router to which my device is connected. – Uzair Dhada Dec 12 '16 at 11:36
  • You need to find the current default route http://stackoverflow.com/questions/6530322/fetching-ip-address-of-router-to-which-iphone-is-connected/23894952#23894952 – Paulw11 Dec 12 '16 at 11:39

0 Answers0