Most efficient way to store IP Address in MySQL [duplicate]

For IPv4 addresses, you may want to store them as an int unsigned and use the INET_ATON() and INET_NTOA() functions to return the IP address from its numeric value, and vice versa. Example: SELECT INET_ATON(‘127.0.0.1’); +————————+ | INET_ATON(‘127.0.0.1’) | +————————+ | 2130706433 | +————————+ 1 row in set (0.00 sec) SELECT INET_NTOA(‘2130706433’); +————————-+ | INET_NTOA(‘2130706433’) … Read more

How can I get a real IP address from DNS query in Swift?

Your code retrieves the address as a “socket address” structure. getnameinfo() can be used to convert the address into a numerical IP string (code recycled from https://stackoverflow.com/a/25627545/1187415, now updated to Swift 2): let host = CFHostCreateWithName(nil,”www.google.com”).takeRetainedValue() CFHostStartInfoResolution(host, .Addresses, nil) var success: DarwinBoolean = false if let addresses = CFHostGetAddressing(host, &success)?.takeUnretainedValue() as NSArray?, let theAddress = … Read more

How to check if an IP address is within a particular subnet

Take a look at IP Address Calculations with C# on MSDN blogs. It contains an extension method (IsInSameSubnet) that should meet your needs as well as some other goodies. public static class IPAddressExtensions { public static IPAddress GetBroadcastAddress(this IPAddress address, IPAddress subnetMask) { byte[] ipAdressBytes = address.GetAddressBytes(); byte[] subnetMaskBytes = subnetMask.GetAddressBytes(); if (ipAdressBytes.Length != subnetMaskBytes.Length) … Read more

How to get the physical interface IP address from an interface

You should use netifaces. It is designed to be cross-platform and contains specialised code for Windows together with a variety of generic versions that work on different UNIX/UNIX-like platforms. As of netifaces version 0.10.0, Python3 is supported. Usage Summary >>> from netifaces import AF_INET, AF_INET6, AF_LINK, AF_PACKET, AF_BRIDGE >>> import netifaces as ni >>> ni.interfaces() … Read more