Tech Off Thread

4 posts

Retrieving the External IP in WinCE

Back to Forum: Tech Off
  • User profile image
    NotSoTragic​Hero

    We have a WinCE device connected to the net via GSM modem.  Our main problem is that we can't remote-connect to this device through VS for deployment and debugging like we can when it is connected via WiFi.  We need the external IP of this device to do so, but "ipconfig" will only give us the IP assigned by the modem, and not the actual external IP.  The device was not flashed with a browser, so we can't even navigate to "whatismyip.com" to get this information.

     

    So long story short, how can I get my devices external IP, or at the very least remote connect to my device through VS when it's using an external modem?

  • User profile image
    davewill

    Sounds like you don't need anything fancy.  Here is a down and dirty.  New .NET CE project with Form1, add textbox1 (multiline) and 1 button.  Basic code found in help file for WebRequest.

     

     

     

     

     

     

     

     

     

     

     

     

    Imports

     

    System.Net

     

    Imports

     

    System.IO

     

    Public

     

     

     

    Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click' Create a request for the URL.

     

     

     

     

    Dim request As WebRequest = WebRequest.Create("http://www.whatismyip.com")' If required by the server, set the credentials.

     

    request.Credentials = CredentialCache.DefaultCredentials

     

     

    ' Get the response.

     

     

     

     

    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)' Display the status.

     

    TextBox1.Text =

     

     

    "Status=" & response.StatusDescription' Get the stream containing content returned by the server.

     

     

     

     

    Dim dataStream As Stream = response.GetResponseStream()' Open the stream using a StreamReader for easy access.

     

     

     

     

    Dim reader As New StreamReader(dataStream)' Read the content.

     

     

     

     

    Dim responseFromServer As String = reader.ReadToEnd()' Display the content.

     

    TextBox1.Text &= responseFromServer

     

     

    ' Cleanup the streams and the response.

     

    reader.Close()

    dataStream.Close()

    response.Close()

    TextBox1.SelectionStart = TextBox1.Text.IndexOf(

    TextBox1.ScrollToCaret()

     

    End

     

    "Your IP Address Is", StringComparison.InvariantCultureIgnoreCase)

    End Sub

    End Class

     

    Edit: Code insert thingy butchered the code.  figured a basic paste was more readable.

  • User profile image
    NotSoTragic​Hero

    davewill said:

    Sounds like you don't need anything fancy.  Here is a down and dirty.  New .NET CE project with Form1, add textbox1 (multiline) and 1 button.  Basic code found in help file for WebRequest.

     

     

     

     

     

     

     

     

     

     

     

     

    Imports

     

    System.Net

     

    Imports

     

    System.IO

     

    Public

     

     

     

    Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click' Create a request for the URL.

     

     

     

     

    Dim request As WebRequest = WebRequest.Create("http://www.whatismyip.com")' If required by the server, set the credentials.

     

    request.Credentials = CredentialCache.DefaultCredentials

     

     

    ' Get the response.

     

     

     

     

    Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)' Display the status.

     

    TextBox1.Text =

     

     

    "Status=" & response.StatusDescription' Get the stream containing content returned by the server.

     

     

     

     

    Dim dataStream As Stream = response.GetResponseStream()' Open the stream using a StreamReader for easy access.

     

     

     

     

    Dim reader As New StreamReader(dataStream)' Read the content.

     

     

     

     

    Dim responseFromServer As String = reader.ReadToEnd()' Display the content.

     

    TextBox1.Text &= responseFromServer

     

     

    ' Cleanup the streams and the response.

     

    reader.Close()

    dataStream.Close()

    response.Close()

    TextBox1.SelectionStart = TextBox1.Text.IndexOf(

    TextBox1.ScrollToCaret()

     

    End

     

    "Your IP Address Is", StringComparison.InvariantCultureIgnoreCase)

    End Sub

    End Class

     

    Edit: Code insert thingy butchered the code.  figured a basic paste was more readable.

    Thanks for your help once again.   Big Smile

     

    That worked beautifully.  However, it looks as if the modem isn't letting me remotely connect to my device through it Sad

  • User profile image
    W3bbo

    NotSoTragicHero said:
    davewill said:
    *snip*

    Thanks for your help once again.   Big Smile

     

    That worked beautifully.  However, it looks as if the modem isn't letting me remotely connect to my device through it Sad

    If your phone is connected via GSM/GPRS/3G/whatever then you'll find it very difficult if not impossible to get in: mobile operator packet networks are often NATted and probably prohibt all incoming connections (after all, why would a mobile device need to run a server/daemon?).

     

    If you're looking to debug software operating under varying mobile network conditions then your best bet is to use the WinCE emulator.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.