08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
84
app/Services/SyS/ImportDbipCountry.php
Normal file
84
app/Services/SyS/ImportDbipCountry.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
namespace App\Services\SyS;
|
||||
|
||||
use App\Models\DbipLookup;
|
||||
use App\Services\dbip\DBIP;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Request;
|
||||
|
||||
class ImportDbipCountry
|
||||
{
|
||||
|
||||
public static function show()
|
||||
{
|
||||
dump("ImportDbipCountry");
|
||||
// dd('check function');
|
||||
|
||||
|
||||
self::read('dbip-country-lite-2024-07.csv', 0, 0);
|
||||
$c = 0;
|
||||
dump("okay counter");
|
||||
dd($c);
|
||||
|
||||
}
|
||||
|
||||
public static function read($filename, $skip = 0, $limit = 0)
|
||||
{
|
||||
/*$find = inet_pton("1.10.128.0");
|
||||
dump($find);
|
||||
dd(DbipLookup::where('ip_start', "<=", $find)->orderBy('ip_start', 'desc')->first());
|
||||
if(!Storage::disk('import')->has($filename)){
|
||||
die("File not found in import folder: ".$filename);
|
||||
}*/
|
||||
|
||||
$path = Storage::disk('import')->path($filename);
|
||||
$fileContents = file($path);
|
||||
$c = 0;
|
||||
foreach ($fileContents as $line) {
|
||||
$row = str_getcsv($line);
|
||||
$row[] = self::addrType($row[0]);
|
||||
|
||||
|
||||
//
|
||||
//base64_encode(file_get_contents($path))
|
||||
// dump($row);
|
||||
\DB::table('dbip_lookup')->insert([
|
||||
'ip_start' => inet_pton($row[0]),
|
||||
'ip_end' => inet_pton($row[1]),
|
||||
'country' => $row[2],
|
||||
'addr_type' => $row[3]
|
||||
]);
|
||||
|
||||
|
||||
//dump(inet_pton($row[0]));
|
||||
/* DbipLookup::create([
|
||||
'ip_start' => ,
|
||||
'ip_end' => inet_pton($row[1]),
|
||||
'country' => $row[2],
|
||||
'addr_type' => $row[3]
|
||||
]);*/
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
private static function addrType($addr) {
|
||||
if (ip2long($addr) !== false) {
|
||||
return "ipv4";
|
||||
} else if (preg_match('/^[0-9a-fA-F:]+$/', $addr) && @inet_pton($addr)) {
|
||||
return "ipv6";
|
||||
}
|
||||
die("unknown address type for {$addr}");
|
||||
}
|
||||
|
||||
public static function store()
|
||||
{
|
||||
$data = Request::all();
|
||||
\Session()->flash('alert-save', true);
|
||||
return back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue