定義了幾個方法,獲取iphone的ip位址。
ipadress.h
01.#define maxaddrs 32
02.extern char *if_names[maxaddrs];
03.extern char *ip_names[maxaddrs];
04.extern char *hw_addrs[maxaddrs];
05.extern unsigned long ip_addrs[maxaddrs];
06.// function prototypes
07.void initaddresses();
08.void freeaddresses();
09.void getipaddresses();
10.void gethwaddresses();
ipaddress.c
03. nsstring *localip;01.#include 02.#include 03.#include 04.#include 05.#include 06.#include 07.#include 08.#include 09.#include 10.#include 11.#include 12.#include 13.#include 14.#include 15.#include "getaddresses.h"
16.#define min(a,b) ((a) < (b) ? (a) : (b))
17.#define max(a,b) ((a) > (b) ? (a) : (b))
18.#define buffersize 4000
19.char *if_names[maxaddrs];
20.char *ip_names[maxaddrs];
21.char *hw_addrs[maxaddrs];
22.unsigned long ip_addrs[maxaddrs];
23.static int nextaddr = 0;
24.void initaddresses()
25.
87.
88. if ((cptr = (char *)strchr(ifr->ifr_name, ':')) != null)
89.
92.
93. if (strncmp(lastname, ifr->ifr_name, ifnamsiz) == 0)
94.
97.
98. memcpy(lastname, ifr->ifr_name, ifnamsiz);
99.
100. ifrcopy = *ifr;
101. ioctl(sockfd, siocgifflags, &ifrcopy);
102. flags = ifrcopy.ifr_flags;
103. if ((flags & iff_up) == 0)
104.
107.
108. if_names[nextaddr] = (char *)malloc(strlen(ifr->ifr_name)+1);
109. if (if_names[nextaddr] == null)
110.
113. strcpy(if_names[nextaddr], ifr->ifr_name);
114.
115. sin = (struct sockaddr_in *)&ifr->ifr_addr;
116. strcpy(temp, inet_ntoa(sin->sin_addr));
117.
118. ip_names[nextaddr] = (char *)malloc(strlen(temp)+1);
119. if (ip_names[nextaddr] == null)
120.
123. strcpy(ip_names[nextaddr], temp);
124. ip_addrs[nextaddr] = sin->sin_addr.s_addr;
125. ++nextaddr;
126. }
127.
128. close(sockfd);
129.}
130.void gethwaddresses()
131.
178. }
179. }
180. }
181. cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
182. }
183. close(sockfd);
184.}
04.}
05.@property (nonatomic, retain) nsstring *localip;
06.- (nsstring *)deviceipadress;
07.@end
02. self.localip = [self deviceipadress];
03. ...
04.}
05.- (nsstring *)deviceipadress {
06. initaddresses();
07. getipaddresses();
08. gethwaddresses();
09.
10. /*
11. int i;
12. nsstring *deviceip;
13. for (i=0; i
得到本機IP位址
方法1 通過網域名稱得到 目標板沒有網域名稱,無法取得 void print ip lst while hp h addr list id null 方法2 ioctl 已驗證 include include int get ip address r1 char ip,char netmask io...
iphone獲取IP位址的方法
下面是不使用蘋果私有 api 獲得 iphone ip 位址的 ipadress.h define maxaddrs 32 extern char if names maxaddrs extern char ip names maxaddrs extern char hw addrs maxaddr...
通過 MAC 位址得到IP的指令碼
通過 mac 位址得到ip的指令碼冷勝魁 seaquester lengshengkui gmail.com 2008 7 16掃瞄某乙個網段,尋找指定網絡卡 由mac位址確定 的ip。bin bash ipprefix 172.21.73 count 1 mac 1 while count 255...