Jump to content
Nytro

Get NAT IP

Recommended Posts

<body>
Your network IP is: <h1 id=list>-</h1> source: <a href="http://net.ipcalf.com/">Make the locals proud.</a>



<script>

// NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;

if (RTCPeerConnection) (function () {
var rtc = new RTCPeerConnection({iceServers:[]});
if (window.mozRTCPeerConnection) { // FF needs a channel/stream to proceed
rtc.createDataChannel('', {reliable:false});
};

rtc.onicecandidate = function (evt) {
if (evt.candidate) grepSDP(evt.candidate.candidate);
};
rtc.createOffer(function (offerDesc) {
grepSDP(offerDesc.sdp);
rtc.setLocalDescription(offerDesc);
}, function (e) { console.warn("offer failed", e); });


var addrs = Object.create(null);
addrs["0.0.0.0"] = false;
function updateDisplay(newAddr) {
if (newAddr in addrs) return;
else addrs[newAddr] = true;
var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
document.getElementById('list').textContent = displayAddrs.join(" or perhaps ") || "n/a";
}

function grepSDP(sdp) {
var hosts = [];
sdp.split('\r\n').forEach(function (line) { // c.f. http://tools.ietf.org/html/rfc4566#page-39
if (~line.indexOf("a=candidate")) { // http://tools.ietf.org/html/rfc4566#section-5.13
var parts = line.split(' '), // http://tools.ietf.org/html/rfc5245#section-15.1
addr = parts[4],
type = parts[7];
if (type === 'host') updateDisplay(addr);
} else if (~line.indexOf("c=")) { // http://tools.ietf.org/html/rfc4566#section-5.7
var parts = line.split(' '),
addr = parts[2];
updateDisplay(addr);
}
});
}
})(); else {
document.getElementById('list').innerHTML = "<code>ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2 | tail -n1</code>";
document.getElementById('list').nextSibling.textContent = "In Chrome and Firefox your IP should display automatically, by the power of WebRTCskull.";
}

</script>

</body>

Sursa: Edit fiddle - JSFiddle (+Demo)

Link to comment
Share on other sites

E adresa de la DHCP, nu de la NAT. NAT si DHCP is 2 functii diferite.

Hai sa fiu putin carcotas.

Adresa IP sa fie functionala are nevoie de NAT. Tu te conectezi la site-ul acela prin NAT pentru ca pe PC-ul tau este configurata o adresa IP locala, asa cum este descrisa in rfc1918.

De unde stii ca am sau nu dhcp ? Uite exemplu functional si fara dhcp:


PC1:
IP Address: 192.168.0.10
Netmask: 255.255.255.0
Gateway: 192.168.0.1

PC2
IP Address: 192.168.0.11
Netmask: 255.255.255.0
Gateway: 192.168.0.1

Router:
LAN IP Address: 192.168.0.1
Netmask 255.255.255.0

DHCP este Dynamic Host Configuration Protocol, functioneaza la fel de bine si fara el.

Si NAT-ul ala daca stai sa te gandesti, e de doua feluri: DNAT si SNAT

Si nu, nu sunt functii. Sunt protocoale.

Network Address Translation (NAT) is a network protocol used in IPv4 networks that allows multiple devices to connect to a public network using the same public IPv4 address. NAT was originally designed in an attempt to help conserve IPv4 addresses.
The Dynamic Host Configuration Protocol (DHCP) is a standardized networking protocol used by servers on an IP network to allocate IP addresses to computers. The purpose of DHCP is to automate the IP address configuration of a computer without a network administrator.

Referinte:

- http://en.wikipedia.org/wiki/DHCP

- http://en.wikipedia.org/wiki/Network_address_translation

Multumesc

-

Cu stima,

Gica Contra, retelist de cartier =))

Edited by aelius
Link to comment
Share on other sites

Aelius, in primul rand, codul de mai sus iti arata o adresa interna primita de la DHCP sau introdusa manual (in exemplul tau), dar totusi nu e o adresa de NAT.

Si nu, nu sunt functii. Sunt protocoale.
- detin functii, dar sunt protocoale. Am scris eu gresit :P
Adresa IP sa fie functionala are nevoie de NAT.
- adresa ta poate sa fie functionala si fara NAT, adica va fi functionala doar in interiorul retelei. Ca sa vezi siteul "acela" care e pe Internet, ai nevoie de functia protocolului NAT. Edited by WarLord
Pentru o explicatie mai buna.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...