How to query a STUN server with JavaScript to get public IP and Port?

stun protocol
turn server
stun server webrtc
stun server github
stun, turn servers
webrtc proxy server
webrtc nat traversal
webrtc ice

I am trying to find some code example to query a STUN server to get my public IP and Port, using JavaScript. Perhaps using the server at

http://www.stunserver.org

While the STUN specification is explained here http://www.ietf.org/rfc/rfc3489.txt ( this is a long document, obviously I don't expect you to read it), I have been unable to find any code example at all, which would make my life easier. Something like

function getMyIPAndPort() {
//query stun server for it
}

Thank you

Very late answer. Have a look at this mini project: https://diafygi.github.io/webrtc-ips/

It does give you the IP, but doesn't seem to give the port. However, if you look at these lines: //match just the IP address var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/ var ip_addr = ip_regex.exec(candidate)[1];

It seems that they remove the port. I am not sure, but you can play with it to find out.

How To TCP NAT Traversal using Node.js and a STUN Server , Connect to the STUN server, and get your public IP and port; Set up the listening socket on the same local port as you are contacting the STUN� I did some tests with a STUN client for windows. Indeed there is a STUN server running on my 3CX server that I could reach at port 5060. However there seems to be some wired firewall / port forwarding issue, preventing access from outside. If I do a STUN request on the local server IP on port 5060, I will get a proper reply.

you can get both local and external IP

 function  determineIps() {
    const pc = new RTCPeerConnection({ iceServers: [ {urls: 'stun:stun.l.google.com:19302'} ] });
    pc.createDataChannel('');
    pc.createOffer().then(offer => pc.setLocalDescription(offer))
    pc.onicecandidate = (ice) => {
        if (!ice || !ice.candidate || !ice.candidate.candidate) {
          console.log("all done.");
          pc.close();   
          return;
        }
        let split = ice.candidate.candidate.split(" ");
        if (split[7] === "host") {
          console.log(`Local IP : ${split[4]}`);
        } else {
          console.log(`External IP : ${split[4]}`);
         }
    };
  }
determineIps();

e.g. https://jsbin.com/zosayiyidu/1/edit?js,console

STUN Client, In few words, it just helps you to map your local computer IP:port to public IP:port. STUN Any,0)); // Query STUN server STUN_Result result = STUN_Client. The STUN server replies with your public IP address and port. Behind a NAT, this is the IP address of the NAT and the port the NAT has chosen to associate to your host in the private network. In most configuration this is enough to get anyone else contacting you using UDP through the IP address and port you have been given.

I've also check the project (https://diafygi.github.io/webrtc-ips), even when it's a fantastic script I did not like too much. I mean, the reason is that it assumes whichs IPs are public and private. If the IP is not 10/8, 172.16/12 or 192.168/16 it's a public IPv4. This is not always true. You can (unfortunately) have an IPv4 address of other range in your LAN and NAT it. This ideas is to obtain the IP address return by the STUN Server, not assume it.

Regards,

Open stun server, In this article, I'm going to run you through the process of getting this set up on an A relay address is a public IP address and port that will forward packets a series of STUN queries against a STUN server located on the public Internet. High performance, production quality STUN server and client library. js file in an 6� First of all, the media server of our gateway has public IP, so the server does not need to collect its own public IP through stun server. The webrtc client first negotiates SDP with the gateway signal server, including ice candidate. The media server assigns IP and port as the ice candidate of the gateway to send to the client.

Java stun server, server for WebRTC Application 2014-03-07 webrtc stun rfc5766turnserver turn How to query a STUN server with JavaScript to get public IP and Port? Aug 10� As a client you can send a request to a publicly available STUN server and have it give back the IP address it sees. Sort of the low level whatismyip.com as it uses no HTTP and no smartly crafted DNS servers but the blazingly fast STUN protocol.

How JavaScript works: WebRTC and the mechanics of peer to peer , Your computer doesn't typically have a static public IP address assigned. Note that in addition to the IP address, a port is also required for network communications. a request for your public-facing IP address is first made to a STUN server. Think of it like your computer making a query to a remote server,� NatTraversal also need an stun server to obtain the mapped (public) IP address (NAT address) and port number that the NAT has allocated for the application's User Datagram Protocol (UDP) connections to remote hosts. Usage: copy www/* to your php server, and chmod all *.txt file, make sure we can read and write to this files through php.

STUN Server, SIP endpoints use the STUN protocol to find out the public IP addresses and ports for You can define STUN servers functionality on a per-realm basis, allowing you Binding Requests from its SIP port to determine the public address it should is set to enabled, you will obtain STUN protocol information for the system. ABOUT TCP . The TCP tool will “ping” an IP address at a specific TCP port and report if the host accepts the connection. The syntax is IPAddress:PortNumber (e.g. 74.125.227.128:80) Great use for this tool is to test if your servers are open on specific ports.

Comments
  • 12 views and no answers..... Chuck Norris please help!!! :(
  • Are you talking about server-side nodejs application or javascript running in a web browser?
  • Oh come on. There should be an Answer.