ios - 用于 ios 开发的 ping 和 arp
<p><p>您好,我是一名 ios 开发人员,我正在尝试编写网络套接字程序。
首先,我试图找到一种获取 arp 表和 icmp 操作(例如 ping)的方法。
我在苹果应用商店找到了很多不错的网络扫描仪,但我真的不知道我应该从哪里开始。 </p>
<p>我担心的只是应用商店被拒绝。</p>
<ul>
<li>我可以在 ios 设备上使用 system() 函数吗? </li>
<li>我知道我不能使用原始套接字编程,如何在没有原始套接字编程的情况下处理 icmp 和 arp 操作?</li>
</ul>
<p>感谢您的关心!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p> <a href="https://github.com/mongizaidi/LAN-Scan" rel="noreferrer noopener nofollow">https://github.com/mongizaidi/LAN-Scan</a> </p>
<p>这个例子应该很适合开始。 (查看 <a href="https://github.com/mongizaidi/LAN-Scan/blob/master/LAN%20Scan/SimplePing.m" rel="noreferrer noopener nofollow">https://github.com/mongizaidi/LAN-Scan/blob/master/LAN%20Scan/SimplePing.m</a> 进行 ping 操作)</p>
<p>注意:<br/>
您无法获取设备的 MAC 地址,但可以解析其他设备的 Mac 地址。<br/>
这是解析主机Mac地址的代码(Apple不会拒绝)</p>
<pre><code>#include <sys/param.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#include "if_types.h"
#include "route.h"
#include "if_ether.h"
#include <netinet/in.h>
#include <arpa/inet.h>
#include <err.h>
#include <errno.h>
#include <netdb.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-(NSString*) ip2mac: (char*) ip
{
int expire_time, flags, export_only, doing_proxy, found_entry;
NSString *mAddr = nil;
u_long addr = inet_addr(ip);
int mib;
size_t needed;
char *host, *lim, *buf, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sin;
struct sockaddr_dl *sdl;
extern int h_errno;
struct hostent *hp;
mib = CTL_NET;
mib = PF_ROUTE;
mib = 0;
mib = AF_INET;
mib = NET_RT_FLAGS;
mib = RTF_LLINFO;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
err(1, "route-sysctl-estimate");
if ((buf = malloc(needed)) == NULL)
err(1, "malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)
err(1, "actual retrieval of routing table");
lim = buf + needed;
for (next = buf; next < lim; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)next;
sin = (struct sockaddr_inarp *)(rtm + 1);
sdl = (struct sockaddr_dl *)(sin + 1);
if (addr) {
if (addr != sin->sin_addr.s_addr)
continue;
found_entry = 1;
}
if (nflag == 0)
hp = gethostbyaddr((caddr_t)&(sin->sin_addr),
sizeof sin->sin_addr, AF_INET);
else
hp = 0;
if (hp)
host = hp->h_name;
else {
host = "?";
if (h_errno == TRY_AGAIN)
nflag = 1;
}
if (sdl->sdl_alen) {
u_char *cp = LLADDR(sdl);
mAddr = , cp, cp, cp, cp, cp];
//ether_print((u_char *)LLADDR(sdl));
}
else
mAddr = nil;
}
if (found_entry == 0) {
return nil;
} else {
return mAddr;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 用于 ios 开发的 ping 和 arp,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/26119587/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/26119587/
</a>
</p>
页:
[1]