perl mysql inetaton

i want to add to mysql my ip addresses like this

perl ipadd.pl --ipclass=185.9.156.0/24

and it will add to 2 columns for each ip address

converted ip address and ip address
3XLcomAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FishMongerCommented:
What have you tried thus far?

What part of the process is giving you trouble?

What is your level of Perl knowledge?

What do you mean by "converted ip address"
0
3XLcomAuthor Commented:
nearly nothing we are just sending values to mysql db via perl
we are good at .net after getting values into mysql we are going on our way ;)
0
FishMongerCommented:
So, are you're saying that you already do have a perl script that is updating the db, but are having trouble getting it to accomplish this task?

You need to be more specific on what you need to accomplish and what problems you're having with your current script.

From what you've posted so far, I have no clue to what you need to accomplish.
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

3XLcomAuthor Commented:
we do not have any thing for this we just need a script which is
when we call it like perl addipclass.pl --ipclass=185.9.156.0/24



INSERT INTO `ipAdresleri` VALUES (3,3104414721,'185.9.156.1'),(4,3104414722,'185.9.156.2'),(5,3104414723,'185.9.156.3'),(6,3104414724,'185.9.156.4'),(7,3104414725,'185.9.156.5'),(8,3104414726,'185.9.156.6'),(9,3104414727,'185.9.156.7'),(10,3104414728,'185.9.156.8'),(11,3104414729,'185.9.156.9'),(12,3104414730,'185.9.156.10'),(13,3104414731,'185.9.156.11'),(14,3104414732,'185.9.156.12'),(15,3104414733,'185.9.156.13'),(16,3104414734,'185.9.156.14'),(17,3104414735,'185.9.156.15'),(18,3104414736,'185.9.156.16'),(19,3104414737,'185.9.156.17'),(20,3104414738,'185.9.156.18'),(21,3104414739,'185.9.156.19'),(22,3104414740,'185.9.156.20'),(23,3104414741,'185.9.156.21'),(24,3104414742,'185.9.156.22'),(25,3104414743,'185.9.156.23'),(26,3104414744,'185.9.156.24'),(27,3104414745,'185.9.156.25'),(28,3104414746,'185.9.156.26'),(29,3104414747,'185.9.156.27'),(30,3104414748,'185.9.156.28'),(31,3104414749,'185.9.156.29'),(32,3104414750,'185.9.156.30'),(33,3104414751,'185.9.156.31'),(34,3104414752,'185.9.156.32'),(35,3104414753,'185.9.156.33'),(36,3104414754,'185.9.156.34'),(37,3104414755,'185.9.156.35'),(38,3104414756,'185.9.156.36'),(39,3104414757,'185.9.156.37'),(40,3104414758,'185.9.156.38'),(41,3104414759,'185.9.156.39'),(42,3104414760,'185.9.156.40'),(43,3104414761,'185.9.156.41'),(44,3104414762,'185.9.156.42'),(45,3104414763,'185.9.156.43'),(46,3104414764,'185.9.156.44'),(47,3104414765,'185.9.156.45'),(48,3104414766,'185.9.156.46'),(49,3104414767,'185.9.156.47'),(50,3104414768,'185.9.156.48'),(51,3104414769,'185.9.156.49'),(52,3104414770,'185.9.156.50'),(53,3104414771,'185.9.156.51'),(54,3104414772,'185.9.156.52'),(55,3104414773,'185.9.156.53'),(56,3104414774,'185.9.156.54'),(57,3104414775,'185.9.156.55'),(58,3104414776,'185.9.156.56'),(59,3104414777,'185.9.156.57'),(60,3104414778,'185.9.156.58'),(61,3104414779,'185.9.156.59'),(62,3104414780,'185.9.156.60'),(63,3104414781,'185.9.156.61'),(64,3104414782,'185.9.156.62'),(65,3104414783,'185.9.156.63'),(66,3104414784,'185.9.156.64'),(67,3104414785,'185.9.156.65'),(68,3104414786,'185.9.156.66'),(69,3104414787,'185.9.156.67'),(70,3104414788,'185.9.156.68'),(71,3104414789,'185.9.156.69'),(72,3104414790,'185.9.156.70'),(73,3104414791,'185.9.156.71'),(74,3104414792,'185.9.156.72'),(75,3104414793,'185.9.156.73'),(76,3104414794,'185.9.156.74'),(77,3104414795,'185.9.156.75'),(78,3104414796,'185.9.156.76'),(79,3104414797,'185.9.156.77'),(80,3104414798,'185.9.156.78'),(81,3104414799,'185.9.156.79'),(82,3104414800,'185.9.156.80'),(83,3104414801,'185.9.156.81'),(84,3104414802,'185.9.156.82'),(85,3104414803,'185.9.156.83'),(86,3104414804,'185.9.156.84'),(87,3104414805,'185.9.156.85'),(88,3104414806,'185.9.156.86'),(89,3104414807,'185.9.156.87'),(90,3104414808,'185.9.156.88'),(91,3104414809,'185.9.156.89'),(92,3104414810,'185.9.156.90'),(93,3104414811,'185.9.156.91'),(94,3104414812,'185.9.156.92'),(95,3104414813,'185.9.156.93'),(96,3104414814,'185.9.156.94'),(97,3104414815,'185.9.156.95'),(98,3104414816,'185.9.156.96'),(99,3104414817,'185.9.156.97'),(100,3104414818,'185.9.156.98'),(101,3104414819,'185.9.156.99'),(102,3104414820,'185.9.156.100'),(103,3104414821,'185.9.156.101'),(104,3104414822,'185.9.156.102'),(105,3104414823,'185.9.156.103'),(106,3104414824,'185.9.156.104'),(107,3104414825,'185.9.156.105'),(108,3104414826,'185.9.156.106'),(109,3104414827,'185.9.156.107'),(110,3104414828,'185.9.156.108'),(111,3104414829,'185.9.156.109'),(112,3104414830,'185.9.156.110'),(113,3104414831,'185.9.156.111'),(114,3104414832,'185.9.156.112'),(115,3104414833,'185.9.156.113'),(116,3104414834,'185.9.156.114'),(117,3104414835,'185.9.156.115'),(118,3104414836,'185.9.156.116'),(119,3104414837,'185.9.156.117'),(120,3104414838,'185.9.156.118'),(121,3104414839,'185.9.156.119'),(122,3104414840,'185.9.156.120'),(123,3104414841,'185.9.156.121'),(124,3104414842,'185.9.156.122'),(125,3104414843,'185.9.156.123'),(126,3104414844,'185.9.156.124'),(127,3104414845,'185.9.156.125'),(128,3104414846,'185.9.156.126'),(129,3104414847,'185.9.156.127'),(130,3104414848,'185.9.156.128'),(131,3104414849,'185.9.156.129'),(132,3104414850,'185.9.156.130'),(133,3104414851,'185.9.156.131'),(134,3104414852,'185.9.156.132'),(135,3104414853,'185.9.156.133'),(136,3104414854,'185.9.156.134'),(137,3104414855,'185.9.156.135'),(138,3104414856,'185.9.156.136'),(139,3104414857,'185.9.156.137'),(140,3104414858,'185.9.156.138'),(141,3104414859,'185.9.156.139'),(142,3104414860,'185.9.156.140'),(143,3104414861,'185.9.156.141'),(144,3104414862,'185.9.156.142'),(145,3104414863,'185.9.156.143'),(146,3104414864,'185.9.156.144'),(147,3104414865,'185.9.156.145'),(148,3104414866,'185.9.156.146'),(149,3104414867,'185.9.156.147'),(150,3104414868,'185.9.156.148'),(151,3104414869,'185.9.156.149'),(152,3104414870,'185.9.156.150'),(153,3104414871,'185.9.156.151'),(154,3104414872,'185.9.156.152'),(155,3104414873,'185.9.156.153'),(156,3104414874,'185.9.156.154'),(157,3104414875,'185.9.156.155'),(158,3104414876,'185.9.156.156'),(159,3104414877,'185.9.156.157'),(160,3104414878,'185.9.156.158'),(161,3104414879,'185.9.156.159'),(162,3104414880,'185.9.156.160'),(163,3104414881,'185.9.156.161'),(164,3104414882,'185.9.156.162'),(165,3104414883,'185.9.156.163'),(166,3104414884,'185.9.156.164'),(167,3104414885,'185.9.156.165'),(168,3104414886,'185.9.156.166'),(169,3104414887,'185.9.156.167'),(170,3104414888,'185.9.156.168'),(171,3104414889,'185.9.156.169'),(172,3104414890,'185.9.156.170'),(173,3104414891,'185.9.156.171'),(174,3104414892,'185.9.156.172'),(175,3104414893,'185.9.156.173'),(176,3104414894,'185.9.156.174'),(177,3104414895,'185.9.156.175'),(178,3104414896,'185.9.156.176'),(179,3104414897,'185.9.156.177'),(180,3104414898,'185.9.156.178'),(181,3104414899,'185.9.156.179'),(182,3104414900,'185.9.156.180'),(183,3104414901,'185.9.156.181'),(184,3104414902,'185.9.156.182'),(185,3104414903,'185.9.156.183'),(186,3104414904,'185.9.156.184'),(187,3104414905,'185.9.156.185'),(188,3104414906,'185.9.156.186'),(189,3104414907,'185.9.156.187'),(190,3104414908,'185.9.156.188'),(191,3104414909,'185.9.156.189'),(192,3104414910,'185.9.156.190'),(193,3104414911,'185.9.156.191'),(194,3104414912,'185.9.156.192'),(195,3104414913,'185.9.156.193'),(196,3104414914,'185.9.156.194'),(197,3104414915,'185.9.156.195'),(198,3104414916,'185.9.156.196'),(199,3104414917,'185.9.156.197'),(200,3104414918,'185.9.156.198'),(201,3104414919,'185.9.156.199'),(202,3104414920,'185.9.156.200'),(203,3104414921,'185.9.156.201'),(204,3104414922,'185.9.156.202'),(205,3104414923,'185.9.156.203'),(206,3104414924,'185.9.156.204'),(207,3104414925,'185.9.156.205'),(208,3104414926,'185.9.156.206'),(209,3104414927,'185.9.156.207'),(210,3104414928,'185.9.156.208'),(211,3104414929,'185.9.156.209'),(212,3104414930,'185.9.156.210'),(213,3104414931,'185.9.156.211'),(214,3104414932,'185.9.156.212'),(215,3104414933,'185.9.156.213'),(216,3104414934,'185.9.156.214'),(217,3104414935,'185.9.156.215'),(218,3104414936,'185.9.156.216'),(219,3104414937,'185.9.156.217'),(220,3104414938,'185.9.156.218'),(221,3104414939,'185.9.156.219'),(222,3104414940,'185.9.156.220'),(223,3104414941,'185.9.156.221'),(224,3104414942,'185.9.156.222'),(225,3104414943,'185.9.156.223'),(226,3104414944,'185.9.156.224'),(227,3104414945,'185.9.156.225'),(228,3104414946,'185.9.156.226'),(229,3104414947,'185.9.156.227'),(230,3104414948,'185.9.156.228'),(231,3104414949,'185.9.156.229'),(232,3104414950,'185.9.156.230'),(233,3104414951,'185.9.156.231'),(234,3104414952,'185.9.156.232'),(235,3104414953,'185.9.156.233'),(236,3104414954,'185.9.156.234'),(237,3104414955,'185.9.156.235'),(238,3104414956,'185.9.156.236'),(239,3104414957,'185.9.156.237'),(240,3104414958,'185.9.156.238'),(241,3104414959,'185.9.156.239'),(242,3104414960,'185.9.156.240'),(243,3104414961,'185.9.156.241'),(244,3104414962,'185.9.156.242'),(245,3104414963,'185.9.156.243'),(246,3104414964,'185.9.156.244'),(247,3104414965,'185.9.156.245'),(248,3104414966,'185.9.156.246'),(249,3104414967,'185.9.156.247'),(250,3104414968,'185.9.156.248'),(251,3104414969,'185.9.156.249'),(252,3104414970,'185.9.156.250'),(253,3104414971,'185.9.156.251'),(254,3104414972,'185.9.156.252'),(255,3104414973,'185.9.156.253'),(256,3104414974,'185.9.156.254'),(257,3104414975,'185.9.156.255'),

Open in new window

0
FishMongerCommented:
I need to work on some other project, but will work up something for you when I have more time.

I'm assuming the first field you're inserting is an auto incrementing "id" field.  Is that correct?
0
3XLcomAuthor Commented:
yes it is and it does not be needed in the insert into statement
0
FishMongerCommented:
Ok, so all that is needed in the insert is the IP address in int and dotted quad format.

Rather than putting the entire range in a single statement, I'd probably do it in a loop like I did in your other question.

The script will need 2 additional modules.  Getopt::Long which is used to handle the parsing of the script args and Net::IP or one of its cousins such as Net::CIDR to handle the address range calculation.

You might like to look over those modules.
0
3XLcomAuthor Commented:
i will but i am sure i can not do it because i am a .net developer . unfortunately we are following sflow and it is not easy on windows & asp.net this is our last part to organize system on cent os side
0
FishMongerCommented:
I didn't build a test database which also means I didn't test this script, so it may need a slight tweak.
#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use Net::IP;
use Getopt::Long;

GetOptions("ipclass=s" => \my $ipclass)
    or die "Invalid command line arguments\n";

$ipclass or die "Missing required -ipclass arg\n";

my $network = Net::IP->new($ipclass) or die Net::IP::Error();

my $dbh = DBI->connect("DBI:mysql:db:db_server", 'user', 'password',
                       {RaiseError => 1})
        or die "Failed to connect to database $DBI::errstr";

my $sth = $dbh->prepare("INSERT INTO ipAdresleri(IP_int, IP_quad)
                         VALUES(?,inet_ntoa(?)");

for (my $ip = $network->intip; $ip <= $network->last_int; $ip++) {
    $sth->execute($ip, $ip);
}

$dbh->disconnect;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FishMongerCommented:
Have you had a chance to test the script?

Do you have any questions about the script?
0
3XLcomAuthor Commented:
I am sorry thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.