使用PHP和MySQL数据库批量查找IPv6地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用PHP和MySQL数据库批量查找IPv6地址相关的知识,希望对你有一定的参考价值。
The code below can be used to lookup IP address in bulk in return of geolocation information using php programming languages and mysql database. In this tutorial, we use the IP2Location LITE database to lookup country of origin from the visitor's IP address. Free databases are available for download at IP2Location LITE database.
<?php //MYSQL configuration $mysql_server = "mysql_server.com"; $mysql_user_name ="User ID"; $mysql_user_pass ="password"; //Connect to database $link = mysql_connect($mysql_server,$mysql_user_name,$mysql_user_pass) or die("could not connect to MySQL Database"); //Check database connection if(!$link) { echo "Database error."; } else { echo "Database is Connected ."; echo "<br><br>"; } //Display for user input echo ""; echo "<title>IP Query in Bulk</title>"; echo " <span>Upload IP list for validation:</span><br><br> <form action="" enctype="multipart/form-data" method="post"> <input name="submit" type="submit" value="Upload & Process"> </form> "; echo ""; //File submitted { //Check for file error if($_FILES["uploaded_file"]["error"] > 0) { echo "Error :" .$_FILES["uploaded_file"]["error"]. "<br>"; } else { echo "<br>"; echo "File Name : " .$_FILES["uploaded_file"]["name"]. "<br>"; echo "Type : " .$_FILES["uploaded_file"]["type"]. "<br>"; echo "Size : " .($_FILES["uploaded_file"]["size"]/ 1024). "KB<br>"; } //Name the output file { $duplicatefile = "result.csv"; echo "Duplicate file deleted ! <br>"; } //Check if uploaded file exists { echo"Uploaded file already exist, Please make sure that both file's content are same. <br>" ; } else { $_FILES["uploaded_file"]["name"]); } //Open file from its location $file = $_FILES["uploaded_file"]["name"]; //To split up the IP Address and fetch data from server { $ipno = Dot2LongIPv6($iplist); $query = "SELECT * FROM ip2location_db11 WHERE ip_to >= $ipno order by ip_to limit 1 "; if(!$query) { echo "Error"; } { $current = ""$iplist","$ipno","{$row['country_code']}","{$row['country_name']}","{$row['region_name']}","{$row['city_name']}","{$row['latitude']}","{$row['longitude']}","{$row['zip_code']}","{$row['time_zone']}"" ; //Output file to the path you want $ans = "result.csv"; } } echo "<br>"; } // Function to convert IP address to IP number (IPv6) function Dot2LongIPv6 ($IPaddr) { $int = inet_pton($IPaddr); $bits = 15; $ipv6long = 0; while($bits >= 0){ if($ipv6long){ $ipv6long = $bin . $ipv6long; } else{ $ipv6long = $bin; } $bits--; } return $ipv6long; } ?>
以上是关于使用PHP和MySQL数据库批量查找IPv6地址的主要内容,如果未能解决你的问题,请参考以下文章