Trying to get NAT's external IPAddress with INATExternalIPAddressCallback in C# -


How do I obtain external Native IP addresses using a library of windows? I am trying to find any information on the INATExternalIPAddress callback, but the use of the unavailable interface in C # has just got an example in C ++. Any guidance would be greatly appreciated.

--Calue

Sorry, I reply from an existing API from Windows Do not give access to the UPNP service, but it helps you

You can also use a STUN-server on the Internet, many are open, every VoIP provider has it.

For example, open a UDP socket, connect to stun.gmx.net on port 3478 and send a packet like this:

  using the system; Using System.Net; Using System.Collections.Generic; Using System.Text; Using System.Security.Cryptography; Name space xxx {class STUNPacket} {static RNGCryptoServiceProvider m_rand = new RNGCryptoServiceProvider (); Private byte [] m_requestid = new byte [16]; Public STUNPacket () {m_rand.GetBytes (m_requestid); } Public byte [] CreateRequest () {byte [] packet = new byte [0x1c] {// header: 0x00,0x01, // Art des stun-pocket: 0x0001 = binding request 0x00,0x08, // Lanze des Paxette Ohne Header 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // Transaction-id / // message -Feature: 0x00,0x03, // Type: change-request 0x00,0x04, // link: 4 bytes 0x00,0x00,0x00,0x00 // wedder ip, not port endure}; For (Int i = 0; I  Packet.Leng) throw new exceptions ("Eididder cap langes, die near meher in pocket pass"); // wenn kein mapped-adress-attribut , Dann überspringen (packet [pause]! = 0] packet [pause + 1]! = 1) {pos + = etaries; continue;} If (atriasis and lt; 8) throw new exceptions ("map-address -Itibate ISST h ("Adresifely von map-address ITIIT IPv4"); Int port = Pocket [Paus + 6] * 256 + packet [pause + 7]; (Pocket [5]! = 1) Throw new exception ]; IP address address = new ipadress (new byte [4] (packet [pin + 8], packet [pause + 9], packet [pause + 10], packet [pause + 11]}; new ipdpoint return (Address, Port);}}}  

}

The IP address given by the Pars-Response should be your IP address like the outside The world sees it.

Note that your external IPs will not be able to get the IP address from your server without the help of an Internet server or directly from your server


Comments