Network IP directly access IP site can be https do not know what
#import "IPAddresses.h"
#import <sys/socket.h>
#import <sys/sockio.h>
#import <sys/ioctl.h>
#import <net/if.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
@implementation ipaddresses
+ (NSString *) getdeviceipaddresses//Intranet static IP
{
int SOCKFD = socket (af_inet,sock_dgram, 0);
if (sockfd <</span> 0) return nil; This error, due to reprint, do not understand, commented out no influence, understand the Great God welcome Guide
Nsmutablearray *ips = [Nsmutablearray array];
int buffersize = 4096;
struct ifconf ifc;
Char Buffer[buffersize], *ptr, Lastname[ifnamsiz], *cptr;
struct Ifreq *ifr, ifrcopy;
Ifc.ifc_len = buffersize;
ifc.ifc_buf = buffer;
if (IOCTL (sockfd,siocgifconf, &IFC) >= 0) {
for (ptr = buffer; ptr < buffer + Ifc.ifc_len;) {
IFR = (struct ifreq *) ptr;
int len =sizeof (struct sockaddr);
if (Ifr->ifr_addr.sa_len > Len) {
Len = ifr->ifr_addr.sa_len;
}
PTR + = sizeof (ifr->ifr_name) + len;
if (ifr->ifr_addr.sa_family!=af_inet) continue;
if (cptr = (char *) STRCHR (ifr->ifr_name, ': '))! = NULL) *cptr = 0;
if (strncmp (LastName, ifr->ifr_name,ifnamsiz) = = 0) continue;
memcpy (LastName, Ifr->ifr_name,ifnamsiz);
Ifrcopy = *IFR;
IOCTL (Sockfd,siocgifflags, &ifrcopy);
if ((ifrcopy.ifr_flags &iff_up) = = 0) continue;
NSString *ip = [NSString stringwithformat:@ "%s", Inet_ntoa (((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr )];
[IPs ADDOBJECT:IP];
}
}
Close (SOCKFD);
NSString *deviceip [email protected] "";
for (int i=0; i < Ips.count; i++) {
if (Ips.count >0) {
DEVICEIP = [NSString stringwithformat:@ "%@", Ips.lastobject];
}
}
return DEVICEIP;
}
Intranet IP
+ (NSString *) deviceipadress {
NSString *address = @ "mobile phone network";
struct Ifaddrs *interfaces = NULL;
struct Ifaddrs *temp_addr = NULL;
int success = 0;
Success = Getifaddrs (&interfaces);
if (success = = 0) {
TEMP_ADDR = interfaces;
while (temp_addr! = NULL) {
if ((*temp_addr). ifa_addr->sa_family = = af_inet) {
if ([[[NSString Stringwithutf8string:temp_addr->ifa_name] isequaltostring:@ "En0"]) {
address = [NSString stringwithutf8string:inet_ntoa ((struct sockaddr_in *) temp_addr->ifa_addr->sin_addr)];
}
}
TEMP_ADDR = temp_addr->ifa_next;
}
}
Freeifaddrs (interfaces);
return address;
}
IOS Get intranet and IP