<!DOCTYPE html>
<html>
<head>
	<title>获取浏览器代理IP</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/7.6.1/adapter.min.js"></script>
	<script type="text/javascript">
		window.onload = function() {
			// 获取浏览器代理IP
			var ipAddress = "";
			fetch("https://api.ipify.org/?format=json")
			.then(response => response.json())
			.then(data => {
				ipAddress = data.ip;
				document.getElementById("ip-address").innerHTML = "浏览器代理IP:" + ipAddress;
			})
			.catch(error => console.error(error));
<pre><code>		// 获取真实IP
		var peerConnectionConfig = {
			'iceServers': [
				{ 'urls': 'stun:stun.l.google.com:19302' }
			]
		};
		var pc = new RTCPeerConnection(peerConnectionConfig);
		pc.createDataChannel(&quot;&quot;);
		pc.createOffer().then(function(offer) {
			pc.setLocalDescription(offer);
		});
		pc.onicecandidate = function(event) {
			if (event.candidate) {
				var ipAddress = event.candidate.candidate.split(&quot; &quot;)[4];
				document.getElementById(&quot;real-ip-address&quot;).innerHTML = &quot;真实IP:&quot; + ipAddress;
				pc.onicecandidate = function() {};
			}
		};
		
		// 获取用户进入时间、所在国家、所在城市
		fetch(&quot;https://ipapi.co/json/&quot;)
		.then(response =&gt; response.json())
		.then(data =&gt; {
			var enterTime = new Date().toLocaleString();
			var country = data.country_name;
			var city = data.city;
			document.getElementById(&quot;enter-time&quot;).innerHTML = &quot;进入时间:&quot; + enterTime;
			document.getElementById(&quot;country&quot;).innerHTML = &quot;所在国家:&quot; + country;
			document.getElementById(&quot;city&quot;).innerHTML = &quot;所在城市:&quot; + city;
			
			// 页面上打字内同自动提交至Php保存Txt
			document.onkeyup = function() {
				var content = document.getElementById(&quot;content&quot;).value;
				fetch(&quot;save.php&quot;, {
					method: &quot;POST&quot;,
					headers: { &quot;Content-Type&quot;: &quot;application/x-www-form-urlencoded&quot; },
					body: &quot;content=&quot; + content
				})
				.then(response =&gt; response.text())
				.then(data =&gt; console.log(data))
				.catch(error =&gt; console.error(error));
			}
		})
		.catch(error =&gt; console.error(error));
	}
&lt;/script&gt;
</code></pre>
</head>
<body>
	<p id="ip-address"></p>
	<p id="real-ip-address"></p>
	<p id="enter-time"></p>
	<p id="country"></p>
	<p id="city"></p>
	<textarea id="content"></textarea>
</body>
</html>
如果你是一名程序员需要写html获取浏览器代理IPwebrtc获取真实IP用户进入时间所在国家所在城市页面上打字内同自动提交至Php保存Txt

原文地址: https://www.cveoy.top/t/topic/bbVb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录