I wrote a code for this. Is it correct?
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl
- @userinput = <STDIN>
- foreach (@userinput)
- @timeData = localtime(time);
- entry_time = join(' ', @timeData);
- {
- $dbh = DBI->connect("DBI:mysql:host=[hostname];
- database=ip_registry","[user]",
- "[password]",{PrintError=>0,RaiseError=>1});
- $sth = $dbh->do("DELETE from ip_map");
- print "\n\nData from ip_map table dropped\n\n";
- $sth = $dbh->prepare("INSERT into ip_map values (?,?,?,?)");
- $count = 0;
- open (PROCESS, "<$file");
- while ($line = <PROCESS>)
- {
- chomp ($line);
- if (($line =~ m/\|ipv4\|/) and ($line !=~ m/\*/)) {
- ($registrar,$country_code,$latitude,$longitude,$ASN,$num_ip,$entry_time,
- ) = split(/\|/, $line);
- @octets_start = split(/\./, $start_ip);
- $long_start = 0;
- foreach $octet_start (@octets_start) {
- $long_start <<= 8;
- $long_start |= $octet_start;
- }
- $long_end = $long_start + ($num_ip-1);
- $count += $sth->execute($country_code,$registrar,$long_start,
- $long_end);
- }
- }
- close PROCESS;
- }