<script>
// Vender Prefixありバージョンの場合も考慮
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
// RTCPeerConnectionコネクションを作成。NAT越えは不要なのでiceServersは未指定
var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};      
// データチャンネルを作成
pc.createDataChannel('');
// Offer送信
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(ice) {
	if (ice && ice.candidate && ice.candidate.candidate) {
            console.log(ice.candidate.candidate);
			// 正規表現を使ってIPアドレスだけ抜き出す。
			var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
			// var ipaddr = document.getElementsByTagName("h1");
			var ipaddr = document.getElementById("logo");
			// ipaddr[0].innerHTML = myIP;
			ipaddr.innerHTML = myIP;
			pc.onicecandidate = noop;
			return myIP;
	}
};
</script>
最終更新:2019年05月21日 00:03