LoginSignup
3
4

More than 5 years have passed since last update.

簡単な IP Address の確認

Last updated at Posted at 2016-04-12

端末のネットワーク設定からの確認やコマンドを叩くのが面倒な場合用

スクリーンショット 2016-04-12 22.13.51.png

<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>
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4