如果你是一名程序员需要写html获取浏览器代理IPwebrtc获取真实IP用户进入时间所在国家所在城市自动提交至Php表格保存txt请写代码
以下是一个可能的解决方案,使用HTML、JavaScript和PHP:
HTML页面:
<!DOCTYPE html>
<html>
<head>
<title>IP信息</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="ip.js"></script>
</head>
<body>
<h1>IP信息</h1>
<p>代理IP: <span id="proxy-ip"></span></p>
<p>真实IP: <span id="real-ip"></span></p>
<p>用户进入时间: <span id="enter-time"></span></p>
<p>所在国家: <span id="country"></span></p>
<p>所在城市: <span id="city"></span></p>
<form id="ip-form" method="post" action="save.php">
<input type="hidden" name="proxy_ip" id="proxy-ip-input">
<input type="hidden" name="real_ip" id="real-ip-input">
<input type="hidden" name="enter_time" id="enter-time-input">
<input type="hidden" name="country" id="country-input">
<input type="hidden" name="city" id="city-input">
<input type="submit" value="提交">
</form>
</body>
</html>
JavaScript代码(保存为ip.js文件):
function getProxyIp() {
return new Promise((resolve, reject) => {
$.get('https://api.ipify.org?format=json', (data) => {
resolve(data.ip);
}).fail(() => {
resolve('');
});
});
}
function getRealIp() {
return new Promise((resolve, reject) => {
const pc = new RTCPeerConnection();
pc.createDataChannel('');
pc.createOffer((offer) => {
pc.setLocalDescription(offer, () => {
const lines = offer.sdp.split('\n');
const line = lines.find((l) => l.indexOf('c=IN IP4') === 0);
const ip = line.split(' ')[2];
resolve(ip);
}, reject);
}, reject);
});
}
function getLocation() {
return new Promise((resolve, reject) => {
$.get('https://ipapi.co/json/', (data) => {
resolve({
country: data.country_name,
city: data.city
});
}).fail(() => {
resolve({
country: '',
city: ''
});
});
});
}
$(document).ready(() => {
const enterTime = new Date().toISOString();
getProxyIp().then((proxyIp) => {
$('#proxy-ip').text(proxyIp);
$('#proxy-ip-input').val(proxyIp);
});
getRealIp().then((realIp) => {
$('#real-ip').text(realIp);
$('#real-ip-input').val(realIp);
});
$('#enter-time').text(enterTime);
$('#enter-time-input').val(enterTime);
getLocation().then((location) => {
$('#country').text(location.country);
$('#country-input').val(location.country);
$('#city').text(location.city);
$('#city-input').val(location.city);
});
$('#ip-form').submit((event) => {
event.preventDefault();
$.post($(event.target).attr('action'), $(event.target).serialize(), () => {
alert('信息已保存');
}).fail(() => {
alert('保存失败');
});
});
});
PHP代码(保存为save.php文件):
<?php
$proxyIp = $_POST['proxy_ip'];
$realIp = $_POST['real_ip'];
$enterTime = $_POST['enter_time'];
$country = $_POST['country'];
$city = $_POST['city'];
$file = fopen('ip.txt', 'a');
if ($file) {
fwrite($file, "$proxyIp\t$realIp\t$enterTime\t$country\t$city\n");
fclose($file);
echo 'success';
} else {
echo 'fail';
}
?>
注意:这里的代码并不是最优的,仅供参考。在实际应用中,需要考虑安全性和性能等方面的问题。
原文地址: https://www.cveoy.top/t/topic/bbWZ 著作权归作者所有。请勿转载和采集!