function Connect-DB
{
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[string]$commandDB,
[string]$dbServer = 'localhost',
[string]$dbName = 'postgres',
[string]$dbUser = 'postgres',
[string]$dbPass = 'postgres',
[string]$port = '5432'
)
$connect = "Driver={PostgreSQL UNICODE(x64)};Server=$dbServer;Port=$port;Database=$dbName;Uid=$dbUser;Pwd=$dbPass;"
$cnDB = New-Object System.Data.Odbc.OdbcConnection($connect)
$dsDB = New-Object System.Data.DataSet
$cnDB.Open()
$adDB = New-Object System.Data.Odbc.OdbcDataAdapter
$adDB.SelectCommand = New-Object System.Data.Odbc.OdbcCommand($commandDB, $cnDB)
$adDB.Fill($dsDB) | out-null
$cnDB.Close()
}
$ipadr1 = "10.62.39.50"
$ipadr2 = "10.62.39.55"
foreach ($i in $ipadr1 .. $ipadr2)
{
$ip = ([System.Net.IPAddress]$i).GetAddressBytes()
[Array]::Reverse($ip) # 10 62 39 50
$ip = $ip -join '.'
[Array]$array = $ip
}
$commandDB = "INSERT INTO public.ip_addresses (ip_range) VALUES ($ip::inet);"
Connect-DB -commandDB $commandDB