간단한 IP 주소 확인

8004 단어 JavaScript
터미널의 네트워크 설정에서 명령을 확인하거나 두드리는 것이 번거로울 때 사용
<html>
  <head>
    <title>IP Address</title>
  </head>
  <body>
    <div>
      <ul id="list"></ul>
    </div>
    <script>
      var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection;
      var RTCSessionDescription = window.RTCSessionDescription || window.RTCSessionDescription;
      var RTCIceCandidate = window.RTCIceCandidate || window.RTCIceCandidate;
      var config = {"iceServers": []};
      var pc = new RTCPeerConnection(config);
      var addresses = [];
      pc.onicecandidate = event => {
        if (event.candidate) {
          var candidate = event.candidate.candidate;
          if (candidate.match("typ host")) {
            var address = candidate.split(" ")[4];
            addresses.push(address);
          }
        } else {
          var filtered = addresses.filter((element, index, self) => {
            return self.indexOf(element) === index;
          });
          filtered.forEach(address => {
              var list = document.getElementById("list");
              var li = document.createElement("li");
              li.textContent = address;
              list.appendChild(li);
          })
          dataChannel.close();
        }
      };
      var dataChannel = pc.createDataChannel("label");
      var options = {};
      pc.createOffer(options)
        .then(sessionDescription => {
          pc.setLocalDescription(sessionDescription)
            .catch(reason => console.error(reason));
        })
        .catch(reason => console.error(reason));
    </script>
  </body>
</html>

좋은 웹페이지 즐겨찾기