下面是不使用蘋果私有 api 獲得 iphone ip 位址的**
/** ipadress.h**
*/#define maxaddrs 32
extern char *if_names[maxaddrs];
extern char *ip_names[maxaddrs];
extern char *hw_addrs[maxaddrs];
extern unsigned long ip_addrs[maxaddrs];
// function prototypes
void initaddresses();
void freeaddresses();
void getipaddresses();
void gethwaddresses();
/** ipaddress.c**/
#include "ipaddress.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
#define buffersize 4000
char *if_names[maxaddrs];
char *ip_names[maxaddrs];
char *hw_addrs[maxaddrs];
unsigned long ip_addrs[maxaddrs];
static int nextaddr = 0;
void initaddresses()
if ((cptr = (char *)strchr(ifr->ifr_name, ':')) != null)
if (strncmp(lastname, ifr->ifr_name, ifnamsiz) == 0)
memcpy(lastname, ifr->ifr_name, ifnamsiz);
ifrcopy = *ifr;
ioctl(sockfd, siocgifflags, &ifrcopy);
flags = ifrcopy.ifr_flags;
if ((flags & iff_up) == 0)
if_names[nextaddr] = (char *)malloc(strlen(ifr->ifr_name)+1);
if (if_names[nextaddr] == null)
strcpy(if_names[nextaddr], ifr->ifr_name);
sin = (struct sockaddr_in *)&ifr->ifr_addr;
strcpy(temp, inet_ntoa(sin->sin_addr));
ip_names[nextaddr] = (char *)malloc(strlen(temp)+1);
if (ip_names[nextaddr] == null)
strcpy(ip_names[nextaddr], temp);
ip_addrs[nextaddr] = sin->sin_addr.s_addr;
++nextaddr;
}close(sockfd);
}void gethwaddresses()
ifr = ifc.ifc_req;
cplim = buffer + ifc.ifc_len;
for (cp=buffer; cp < cplim; )}}
}cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len);
}close(sockfd);
}test:
#import "ipadress.h"
..........
- (nsstring *)deviceipadress
- (void)viewdidload
獲取iphone的IP位址原始碼
定義了幾個方法,獲取iphone的ip位址。ipadress.h ipaddress.c nsstring localip property nonatomic,retain nsstring localip nsstring deviceipadress end self.localip self...
獲取IP位址方法
方法一 方法二 方法三 string strhostname system.net.dns.gethostname string clientipaddress system.net.dns.gethostaddresses strhostname getvalue 0 tostring 但如果客戶...
PHP獲取IP位址的方法,防止偽造IP位址注入攻擊
原文 php獲取ip位址的方法,防止偽造ip位址注入攻擊 php獲取ip位址的方法 獲取客戶端ip位址 x forwarded for 是 伺服器通過 http headers 提供的客戶端ip。伺服器可以偽造任何ip。要防止偽造,不要讀這個ip即可 同時告訴使用者不要用http param int...