在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1. Via NDK Refer Delphi Call getifaddrs and freeifaddrs on Android uses Posix.Ifaddrs, Posix.SysSocket, Posix.ArpaInet, Posix.NetinetIn; var FPifaddrs: Pifaddrs; FPin_addr: Pointer; Fsa_family: sa_family_t; FPtrWrapper: TPtrWrapper; begin getifaddrs(FPifaddrs); FPtrWrapper := TMarshal.AllocMem(INET6_ADDRSTRLEN); while FPifaddrs <> Nil do begin Fsa_family := FPifaddrs.ifa_addr.sa_family; if (Fsa_family = AF_INET) or (Fsa_family = AF_INET6) then begin if Fsa_family = AF_INET then FPin_addr := @Psockaddr_in(FPifaddrs.ifa_addr).sin_addr else FPin_addr := @Psockaddr_in6(FPifaddrs.ifa_addr).sin6_addr; inet_ntop(Fsa_family, FPin_addr, FPtrWrapper.ToPointer, INET6_ADDRSTRLEN); Writeln(TMarshal.ReadStringAsAnsi(FPtrWrapper)); end; FPifaddrs := FPifaddrs.ifa_next; end; TMarshal.FreeMem(FPtrWrapper); end;
2. Via JNI uses Androidapi.JNI.Net, Androidapi.JNI.Java.Net, Androidapi.JNI.JavaTypes, Androidapi.Helpers; var FJEnumOfNet: JEnumeration; FJNet: JNetworkInterface; FJEnumOfAddr: JEnumeration; FJAddr: JInetAddress; begin FJEnumOfNet := TJNetworkInterface.JavaClass.getNetworkInterfaces; while FJEnumOfNet.hasMoreElements do begin FJNet := TJNetworkInterface.Wrap(FJEnumOfNet.nextElement); FJEnumOfAddr := FJNet.getInetAddresses; while FJEnumOfAddr.hasMoreElements do begin FJAddr := TJInetAddress.Wrap(FJEnumOfAddr.nextElement); Writeln(JStringToString(FJAddr.getHostAddress.toString)); end; end; end; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论