Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get the Internet IP

How to get the Internet IP

Scheduled Pinned Locked Moved C#
csharptutorialquestion
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sixefftee
    wrote on last edited by
    #1

    I need to be able to run an application on a local pc that is behind a firewall and get the internet ip address for the computer. does anyone know how this can be done in .net?

    N H T 3 Replies Last reply
    0
    • S sixefftee

      I need to be able to run an application on a local pc that is behind a firewall and get the internet ip address for the computer. does anyone know how this can be done in .net?

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      You should take a look at the IPAddress Class[^] on MSDN[^]. - Nick Parker
      My Blog | My Articles

      1 Reply Last reply
      0
      • S sixefftee

        I need to be able to run an application on a local pc that is behind a firewall and get the internet ip address for the computer. does anyone know how this can be done in .net?

        H Offline
        H Offline
        Heath Stewart
        wrote on last edited by
        #3

        If you want the IP address of the computer behind the firewall (and you're outside), then you must define your protocol such that the IP address is included in the TCP (or UDP) message - not in the header (which is masked using the firewall's IP address with a NAT'd firewall). It probably won't do you much good, though, since 1) masked IP addresses are typically in the reserved range and don't route throughout the Internet, and 2) you still can't communicate with it directly.

        Microsoft MVP, Visual C# My Articles

        A 1 Reply Last reply
        0
        • S sixefftee

          I need to be able to run an application on a local pc that is behind a firewall and get the internet ip address for the computer. does anyone know how this can be done in .net?

          T Offline
          T Offline
          TalkingBabb0t
          wrote on last edited by
          #4

          I would try this method that I used. IPAddress ipAdress = IPAddress.Any; IPEndPoint Enp = new IPEndPoint(ipAdress, 60001); Socket m_soc = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp); m_soc.Bind(Enp); //then do this to get the current IP&source port System.Windows.Forms.MessageBox.Show(m_soc.LocalEndPoint.ToString()); Try that..should work in a x.x.x.x:x format :-D

          1 Reply Last reply
          0
          • H Heath Stewart

            If you want the IP address of the computer behind the firewall (and you're outside), then you must define your protocol such that the IP address is included in the TCP (or UDP) message - not in the header (which is masked using the firewall's IP address with a NAT'd firewall). It probably won't do you much good, though, since 1) masked IP addresses are typically in the reserved range and don't route throughout the Internet, and 2) you still can't communicate with it directly.

            Microsoft MVP, Visual C# My Articles

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            ok but, here's the thing i'm not outside i have a client app that runs on the client pc and i have a server app that needs the ip. the problem i had is that i need the client ip so i can route connection from the server to the client kind of like a one chat. the only restriction is i can't give out the server ip. so that leaves me with the only one option to have the server connect to client. so that's my situation.

            B H 2 Replies Last reply
            0
            • A Anonymous

              ok but, here's the thing i'm not outside i have a client app that runs on the client pc and i have a server app that needs the ip. the problem i had is that i need the client ip so i can route connection from the server to the client kind of like a one chat. the only restriction is i can't give out the server ip. so that leaves me with the only one option to have the server connect to client. so that's my situation.

              B Offline
              B Offline
              Broken God
              wrote on last edited by
              #6

              Well, if you intend on actually connecting to a client behind a firewall, make sure you set up port forwarding for it. As for getting the IP, your only choice is to use a machine outside the local network. Something like make a HTTP query to whatsmyip.com and extract the result.

              1 Reply Last reply
              0
              • A Anonymous

                ok but, here's the thing i'm not outside i have a client app that runs on the client pc and i have a server app that needs the ip. the problem i had is that i need the client ip so i can route connection from the server to the client kind of like a one chat. the only restriction is i can't give out the server ip. so that leaves me with the only one option to have the server connect to client. so that's my situation.

                H Offline
                H Offline
                Heath Stewart
                wrote on last edited by
                #7

                That's a pretty dumb restriction - knowing an IP isn't a problem; it's making sure that the server is secure that is. Even if the server establishes a connection with the client, it's easy to determine the IP address (it's in the TCP/IP headers!). But you probably can't do anything about that. If both the client and server are on the same LAN, you can use a multicast group. See the class documentation[^] for the MulticastOption class in the .NET Framework SDK for more details and a client/server example. This uses UDP to send datagrams (connectionless IP, unlike TCP) to a multicast IP address (reserved range; it's not the server's IP). Everyone in the multicast group can receive the message and process it.

                Microsoft MVP, Visual C# My Articles

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups