Sample Header Ad - 728x90

Database Administrators

Q&A for database professionals who wish to improve their database skills

Latest Questions

4 votes
2 answers
2201 views
Sqlserver IPV6 handling function or numeric conversion
I'm looking for ways to handle IPv6 CIDR address ranges in SqlServer. The data I obtained is formatted as bellow and has these columns : Int_IP_Start, Int_IP_End, CIDR_Range, ASN, Name for IPv4 "2868826112","2868826623","170.254.208.0/23","265116","Wave Net" "2868827136","2868828159","170.254.212.0/...
I'm looking for ways to handle IPv6 CIDR address ranges in SqlServer. The data I obtained is formatted as bellow and has these columns : Int_IP_Start, Int_IP_End, CIDR_Range, ASN, Name for IPv4 "2868826112","2868826623","170.254.208.0/23","265116","Wave Net" "2868827136","2868828159","170.254.212.0/22","265381","Furtado & Furtado Provedores LTDA" "2868828928","2868829183","170.254.219.0/24","264770","Leonir Remussi (KDMNET)" "2868829184","2868829439","170.254.220.0/24","265373","NET TELECOMUNICACOES LTDA - ME" "2868829440","2868829695","170.254.221.0/24","265373","NET TELECOMUNICACOES LTDA - ME" "2868830208","2868831231","170.254.224.0/22","265382","TELECOM LTDA ME" "2868831232","2868831487","170.254.228.0/24","27951","Media Commerce Partners S.A" And this is the same but for IPv6 "58568835385568506466387976054061924352","58568835464796668980652313647605874687","2c0f:f288::/32","328039","JSDAAV-ZA-Telecoms-AS" "58568842991472107835764385034281156608","58568842991473316761583999663455862783","2c0f:f2e8::/48","37182","TERNET" "58568844892948008178108487279335964672","58568844892949217103928101908510670847","2c0f:f300::/48","37153","Hetzner" "58568847428249208634567290272742375424","58568847507477371148831627866286325759","2c0f:f320::/32","37126","BELL-TZ" "58568849329725108976911392517797183488","58568849408953271491175730111341133823","2c0f:f338::/32","327983","Interworks-Wireless-Solutions" The numerical reprensentation of a single IPv6 is quite large as the address space is the equivalent of a 128bit integer. The goal here is to have a way for a database query to return wether or not an IP is part of one of the stored ranges that came from the CSV. For IPv4 that's easy, you take the IP and convert it to it's INT32 equivalent. Since there is no INT128 datatype in SqlServer I've got the following questions : -Is there a way to create a custom type that would store a bigint of 128bits ? (Only need to perform Greater than or lesser than operations) -Is there a way to properly handle IP address ranges in SqlServer ? **EDIT:** Here is the largest number an IPv6 address can represent : string LongestIp = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"; var SerializedIp = IPNetwork.ToBigInteger(IPAddress.Parse(LongestIp)); Console.WriteLine(SerializedIp.ToString()); This c# code outputs 340282366920938463463374607431768211455 Trying to insert this declare @ipv6Decimals table (Ip decimal(38,0)); insert into @ipv6Decimals (Ip) values (58568844892949217103928101908510670847); --this is okay, --When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1 insert into @ipv6Decimals (Ip) values (99999999999999999999999999999999999999); --This is the largest numeric(38,0) will fit insert into @ipv6Decimals (Ip) values (340282366920938463463374607431768211455);-- This is too large Msg 1007, Level 15, State 1, Line 3 The number '340282366920938463463374607431768211455' is out of the range for numeric representation (maximum precision 38).
A_V (1374 rep)
Aug 21, 2018, 12:57 PM • Last activity: Jun 19, 2025, 10:37 AM
1 votes
1 answers
43 views
Ipv6 creating table load data and retriving in mysql using ip_poly
``` CREATE TABLE `ipv6_table` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `ip_poly` POLYGON NOT NULL, `start_network` BIGINT(20) NOT NULL DEFAULT '0', `end_network` BIGINT(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), SPATIAL KEY `idx_ip_poly` (`ip_poly`) ) ENGINE=Innodb; LOAD DATA LOCAL INFILE...
CREATE TABLE ipv6_table (
  id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  ip_poly POLYGON NOT NULL,
  start_network BIGINT(20) NOT NULL DEFAULT '0',
  end_network BIGINT(20) NOT NULL DEFAULT '0',
  PRIMARY KEY (id),
  SPATIAL KEY idx_ip_poly (ip_poly)
) ENGINE=Innodb; 
  
LOAD DATA LOCAL INFILE '/var/lib/mysql-files/19225.csv'
INTO TABLE ipv6_table
FIELDS TERMINATED BY ',' ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
(
  @start_network,
  @end_network )
SET
  id = NULL,
	ip_poly = ST_GeomFromText(CONCAT(
	  'POLYGON((',
	  @start_network - 1, ' -1, ',
	  @end_network + 1, ' -1, ',
	  @end_network + 1, ' 1, ',
	  @start_network - 1, ' 1, ',
	  @start_network - 1, ' -1))'
	)),
  start_network = @start_network,
  end_network = @end_network ;	
  
SELECT * FROM ipv6_table WHERE ST_Intersects(ip_poly, ST_GEOMFROMTEXT(concat('POINT(', 2306128953120655672, ' 0)')));
I have raw data in csv file like this
2306128950956392448,2306128951224827903
2306128951224827904,2306128951241605119
2306128951241605120,2306128951493263359
2306128951493263360,2306128951510040575
2306128951510040576,2306128952030134271
2306128952030134272,2306128952046911487
Like this I'm trying to create table for Ipv6 data. and I'm loading data from csv file into it and I'm trying to fetch ipv6 data using start_network or end_network or range between them but it is returning multiple data. can anyone help me in this.
Aravind (11 rep)
Feb 26, 2025, 10:17 PM • Last activity: Feb 27, 2025, 05:40 AM
3 votes
1 answers
2291 views
How to set IP segment and connection string with IPv6?
For this PostgreSQL configuration example: https://repmgr.org/docs/4.4/quickstart-authentication.html ``` local replication repmgr trust host replication repmgr 127.0.0.1/32 trust host replication repmgr 192.168.1.0/24 trust local repmgr repmgr trust host repmgr repmgr 127.0.0.1/32 trust host repmgr...
For this PostgreSQL configuration example: https://repmgr.org/docs/4.4/quickstart-authentication.html
local   replication   repmgr                              trust
    host    replication   repmgr      127.0.0.1/32            trust
    host    replication   repmgr      192.168.1.0/24          trust

    local   repmgr        repmgr                              trust
    host    repmgr        repmgr      127.0.0.1/32            trust
    host    repmgr        repmgr      192.168.1.0/24          trust
I have two questions. # Question 1 This is how a netmask looks for IPv4: 192.168.1.0/24. How to do with an IPv6 IP address like 230b:c010:103:5858:a6a3:3:0:1? # Question 2 If use JDBC to connect to a PostgreSQL server, I can use a connection URL containing 192.168.1.11:5432. How to do it with IPv6? Is it like 230b:c010:103:5858:a6a3:3:0:1:5432?
rawmain (359 rep)
Dec 18, 2019, 06:17 AM • Last activity: Dec 18, 2019, 09:52 AM
2 votes
1 answers
1404 views
Unable to search between IPv6 range when converting string IP Address to VARBINARY(16)
I am attempting to search for IPGeolocation data, which is presented by the data vendor as a start and end range for both IPv4 and IPv6. However, when I convert the IP that is provided, I am getting incorrect results. To search by range, I am converting the `VARCHAR(39)` representation of the IPv6 i...
I am attempting to search for IPGeolocation data, which is presented by the data vendor as a start and end range for both IPv4 and IPv6. However, when I convert the IP that is provided, I am getting incorrect results. To search by range, I am converting the VARCHAR(39) representation of the IPv6 into a VARBINARY (i.e., Hex) and then using the BETWEEN operator to see if the searched Hex value falls within a specific range. **Query logic:** SELECT CONVERT(VARBINARY(16), '2600:8800:6a06:2000:1d29:3b7:8c7c:271b') **Search:** IP: 2600:8800:6a06:2000:1d29:3b7:8c7c:271b IpHex: 0x323630303A383830303A366130363A32 **Result 1** IpStart: 2600:8800:490:0:0:0:0:0 IpStartHex: 0x323630303A383830303A3439303A303A IpEnd: 2600:8800:77f:ffff:ffff:ffff:ffff:ffff IpEndHex: 0x323630303A383830303A3737663A6666 **Result 2** IpStart: 2600:8800:6a06:1d01:0:0:0:0 IpStartHex: 0x323630303A383830303A366130363A31 IpEnd: 2600:8800:6a06:24ff:ffff:ffff:ffff:ffff IpEndHex: 0x323630303A383830303A366130363A32
J Weezy (199 rep)
Feb 26, 2019, 05:46 PM • Last activity: Feb 26, 2019, 07:43 PM
1 votes
1 answers
2947 views
Disabling IPV6 on Always on availability group
In our environment we only have one network adapters for the Replicas and IPV4 is being used. By default the IPV6 is also enabled. My question is will there be any problems if I unchecked IPV6 from the Adapter properties
In our environment we only have one network adapters for the Replicas and IPV4 is being used. By default the IPV6 is also enabled. My question is will there be any problems if I unchecked IPV6 from the Adapter properties
SQL_NoExpert (1117 rep)
Nov 1, 2018, 02:41 PM • Last activity: Nov 1, 2018, 04:53 PM
Showing page 1 of 5 total questions