ios 如何在 iPhone 中 Ping 或检查特定 IP 地址的服务器是否可用/连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8132827/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:23:44  来源:igfitidea点击:

How to Ping or check if server of particular IP Address is available/connected in iPhone

iphoneiosxcodeip-address

提问by P.J

I want to Ping or Lookup a particular IP address of server if it is connected or available at that particular time or not in my iPhone application.

我想 Ping 或查找服务器的特定 IP 地址,如果它在特定时间连接或可用或不在我的 iPhone 应用程序中。

I searched a lot over internet but could not find any relevant result for same.

我在互联网上搜索了很多,但找不到任何相关的结果。

Please help me as I am new to this field.

请帮助我,因为我是这个领域的新手。

Thanks in advance.

提前致谢。

回答by nanjunda

Apple provides reachability classes you can use the class and

Apple 提供了可达性类,您可以使用该类和

You can download reachability.hand Reachability.m

你可以下载reachability.hReachability.m

And use this as

并将其用作

Reachability* reachability = [[Reachability reachabilityWithHostName: @"www.apple.com"] retain];
NetworkStatus netStatus = [reachability currentReachabilityStatus];

netStatus gives the reachabilty of the server.

netStatus 给出了服务器的可达性。

回答by driedler

If you want to ping the server, try this:

如果你想ping服务器,试试这个:

SimplePing

简单Ping

It allows for you to ping by either hostname or IP.

它允许您通过主机名或 IP 进行 ping。

回答by Manali

You need Apple's ReachabilitySample Application.

您需要 Apple 的ReachabilitySample Application。