inet-aton

How to do wildcard search for IP addresses using INET_ATON in MySQL?

僤鯓⒐⒋嵵緔 提交于 2020-01-23 17:18:45
问题 I found this method to store IP addresses in MySQL database as integer using INET_ATON: https://stackoverflow.com/a/5133610/4491952 Since IPv4 addresses are 4 byte long, you could use an INT (UNSIGNED) that has exactly 4 bytes: `ipv4` INT UNSIGNED And INET_ATON and INET_NTOA to convert them: INSERT INTO `table` (`ipv4`) VALUES (INET_ATON("127.0.0.1")); SELECT INET_NTOA(`ipv4`) FROM `table`; For IPv6 addresses you could use a BINARY instead: `ipv6` BINARY(16) And use PHP’s inet_pton and inet

Are there any .NET Framework Method that does INET_ATON()

断了今生、忘了曾经 提交于 2019-12-10 23:57:28
问题 That does this calculation below address = '174.36.207.186' ( o1, o2, o3, o4 ) = address.split('.') integer_ip = ( 16777216 * o1 ) + ( 65536 * o2 ) + ( 256 * o3 ) + o4 回答1: string s = "174.36.207.186"; uint i = s.Split('.') .Select(uint.Parse) .Aggregate((a, b) => a * 256 + b); 回答2: You can parse the numbers into a byte array, then use BitConverter.ToInt32 to put them together into an int: byte[] parts = address.Split('.').Select(Byte.Parse).ToArray(); if (BitConverter.IsLittleEndian) { Array