--- title: "Add IP ranges and map credentials with a SQL script" slug: "add-ip-ranges-and-map-credentials-with-a-sql-script" updated: 2026-09-09T15:34:58Z published: 2026-09-09T15:34:58Z canonical: "docs.lansweeper.com/add-ip-ranges-and-map-credentials-with-a-sql-script" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.lansweeper.com/llms.txt > Use this file to discover all available pages before exploring further. # Add IP ranges and map credentials with a SQL script If you need to add several IP range scanning targets to a scanning server and control which scanning credentials each range uses, a database script is faster than the web console. This script adds an IP range, maps credentials to it in priority order, and optionally adds an Active Directory domain. To configure a whole scanning server in one pass instead, see [Auto-configure a scanning server with a SQL script](/classic/docs/auto-configure-a-scanning-server-with-a-sql-script). Back up your database first Writing directly to the Lansweeper database bypasses the web console and can break your installation if a value is wrong. Back up your database before you continue, as explained in [Back up your installation](/classic/docs/back-up-your-installation). Test the script on a non-production installation first. ## Prerequisites - The scanning server is installed and linked to the same database. - You've already added the scanning credentials in the web console, under **Scanning > Scanning credentials**. Credentials are shared across every scanning server linked to the same database. - You have access to the SQL Server instance that hosts the `lansweeperdb` database, and SQL Server Management Studio to run queries. ## Find your credential IDs The credential mapping links an IP range to credentials by their `CredID`. List your credentials and their IDs first: ``` SELECT CredID, Credname FROM [lansweeperdb].[dbo].[tsysCredentials] ``` Note the `CredID` of each credential you want to map to the IP range. ## Choose an IP range ID The script sets an explicit `IprangeID` (the example uses `10`) and reuses it to link the credential mappings to the range. Pick a value that isn't already in use: ``` SELECT IprangeID FROM [lansweeperdb].[dbo].[tsysIPScanRanges] ``` Use an unused value everywhere the script references `IprangeID`. The credential mappings also set an explicit `ipRangeCredentialsId` (the example uses `1` to `5`); pick unused values for those too. If you add an Active Directory domain, pick an unused `AsDomainId` the same way. ## Set your values Before running the script, replace these values: | Value | Example | What to enter | | --- | --- | --- | | `IprangeID` | `10` | An unused IP range ID (see above). Use the same value in the range and the credential mappings. | | `Servername` | `MYSCANNER` | The scanning server's name, exactly as it appears in the web console. | | `Ipstart` / `Ipend` | `10.20.1.1` / `10.20.1.100` | First and last IP address of the range. | | `Description` | `My IP Range` | A label for the IP range. | | `CredID` | `10`, `12`, `13`, `16`, `17` | The IDs of the credentials to map, from `tsysCredentials`. | | `Priority` | `1` to `5` | The order credentials are tried. A lower number is tried first. | ## Run the script 1. Open SQL Server Management Studio and connect to the SQL Server instance that hosts the `lansweeperdb` database. 2. Open a **New Query** window and paste the script below. 3. Replace the example values, adding or removing IP ranges and credential mappings as needed. 4. Run the script. 5. Restart the **Lansweeper Server** service on the scanning server so it reloads the new IP range and credentials from the database. Direct database changes don't take effect until the service restarts. ``` USE [lansweeperdb] GO -- Add the IP range SET IDENTITY_INSERT [dbo].[tsysIPScanRanges] ON INSERT [dbo].[tsysIPScanRanges] ([IprangeID], [Servername], [Ipstart], [Ipend], [Enabled], [PingTimeout], [IPIgnoreWindows], [DontPing], [Day1], [Day2], [Day3], [Day4], [Day5], [Day6], [Day7], [Day1time], [Day2time], [Day3time], [Day4time], [Day5time], [Day6time], [Day7time], [LastIPscan], [NoSSH], [Recurring], [Minutes], [Waittime], [SSHport], [SavePingedIP], [IPIgnoreKnownWindows], [Description], [SIPport], [ScanNow], [CloudId]) VALUES (10, N'MYSCANNER', N'10.20.1.1', N'10.20.1.100', 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), CAST(N'1900-01-01T05:00:00.000' AS DateTime), NULL, 0, 0, 0, 0, 22, 1, 0, N'My IP Range', 5060, 0, NULL) SET IDENTITY_INSERT [dbo].[tsysIPScanRanges] OFF GO -- Map credentials to the IP range, in priority order SET IDENTITY_INSERT [dbo].[tsysIPRangeCredentials] ON INSERT [dbo].[tsysIPRangeCredentials] ([IPrangeID], [CredID], [Priority], [ipRangeCredentialsId], [CloudId]) VALUES (10, 10, 2, 1, NULL) INSERT [dbo].[tsysIPRangeCredentials] ([IPrangeID], [CredID], [Priority], [ipRangeCredentialsId], [CloudId]) VALUES (10, 12, 1, 2, NULL) INSERT [dbo].[tsysIPRangeCredentials] ([IPrangeID], [CredID], [Priority], [ipRangeCredentialsId], [CloudId]) VALUES (10, 13, 3, 3, NULL) INSERT [dbo].[tsysIPRangeCredentials] ([IPrangeID], [CredID], [Priority], [ipRangeCredentialsId], [CloudId]) VALUES (10, 16, 4, 4, NULL) INSERT [dbo].[tsysIPRangeCredentials] ([IPrangeID], [CredID], [Priority], [ipRangeCredentialsId], [CloudId]) VALUES (10, 17, 5, 5, NULL) SET IDENTITY_INSERT [dbo].[tsysIPRangeCredentials] OFF GO -- Optional: add an Active Directory domain SET IDENTITY_INSERT [dbo].[tsysASDomains] ON INSERT [dbo].[tsysASDomains] ([AsDomainId], [Servername], [Domainname], [Netbiosname], [Description], [ScanNow], [LastScanned], [Enabled], [ErrorText], [CloudId], [IntervalInSeconds], [MinRescanTimeInSeconds], [MaxRescanTimeInSeconds]) VALUES (10, N'MYSCANNER', N'MYDOMAIN.local', N'MYDOMAIN', N'MyDomain HQ AD', 0, NULL, 0, N'', NULL, 900, 72000, 172800) SET IDENTITY_INSERT [dbo].[tsysASDomains] OFF GO ``` The Active Directory domain in the script is added disabled (`Enabled` is `0`). Enable it in the web console under **Scanning > Scanning targets**, or set `Enabled` to `1` in the script to make it active right away. ## Verify the configuration Open the web console and confirm the new IP range and its credentials: 1. Go to **Scanning > Scanning targets** and confirm the IP range is listed for the scanning server. 2. Open the IP range and confirm the mapped credentials appear in the priority order you set.