Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Open a chrome web browser

  2. Open the inspector (right-click>inspect)

  3. Choose the ‘Console’ tab

  4. paste in this block of code

    Code Block
    const iceServers = [
        {
            urls: 'stun:stun.l.google.com:19302?transport=udp'
        },
    ];
    
    const pc = new RTCPeerConnection({
    	iceServers
    });
    
    pc.onicecandidate = (e) => {
        if (!e.candidate) return;
    
        // Display candidate string e.g
        // candidate:842163049 1 udp 1677729535 XXX.XXX.XX.XXXX 58481 typ srflx raddr 0.0.0.0 rport 0 generation 0 ufrag sXP5 network-cost 999
        console.log(e.candidate.candidate);
    
        if(e.candidate.type == "srflx"){
            console.log("The STUN server is reachable!");
            console.log(`   Your Public IP Address is: ${e.candidate.address}`);
        }
    };
    
    // Log errors:
    // Remember that in most of the cases, even if its working, you will find a STUN host lookup received error
    // Chrome tried to look up the IPv6 DNS record for server and got an error in that process. However, it may still be accessible through the IPv4 address
    pc.onicecandidateerror = (e) => {
        console.error(e);
    };
    
    pc.createDataChannel('stun-test');
    pc.createOffer().then(offer => pc.setLocalDescription(offer));
    
  5. Press enter

  6. Observe the response

...