Results 1 to 19 of 19

Thread: Get Internet IP

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37

    Get Internet IP

    Hello,

    I have a DSL modem and want to get the Internet IP address that has been assigned to me by my ISP via VB .NET code. I've found examples here that work for VB6, but can't find code for VB .NET. Anyone got anything that can help me?

    Thanks,

    Neofree

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Unfortuantely, it is not possible to retrieve an external IP address when the machine is behind a router on a network.

    The code you have for VB6 does grab your external IP address, but only because it connects to an external site, such as ShowMyIP.COM, that exists simply to return your IP address.

    However, sites such as those, only allow a request every 10 seconds or so, any more than that, and your code will be denied.

    Worse, if the site ever closes, your code will break.

    This is a problem that will and can only be solved by the router manufacturers. There should be a standard developed to include a function that will return the currently assignd external address, however, I don't see that happening anytime soon unfortunately.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    How interesting I was told you can use ipconfig to get the IP Address by my ISP. And the code I was using is an API call.

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Post the VB6 code API decleration

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    The code I'm trying to port is:

    http://www.vbforums.com/showthread.p...ghlight=dsl+ip

    I changed this line to remove the "As Any" and "As Integer" parameters:

    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination, ByRef Source, ByVal Length)

    Before it would not compile, now it compiles and runs but gives error (After removing on error statement):

    An unhandled exception of type 'System.NullReferenceException' occurred in Project1.exe

    Additional information: Object reference not set to an instance of an object.

    And it highlights this line as cause of the error:

    CopyMemory(Listing.dEntrys, bBytes(0), 4)

    Thanks,

    Neofree

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    The code you referred to only returns the correct address if the machine itself handles the DNS (the computer connects to the internet). When your behind a router, the router handles it, because the router connects to the internet.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    My configuration is:

    PC -> NIC -> ActionTec DSL Gateway -> DSL Line/ISP

  8. #8
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    From your initial post, it will work if you don't have a router between your modem and your computer.

    In which case:
    VB Code:
    1. Option Strict Off
    2. Imports system
    3. Imports System.Net.DNS
    4.   Public Class GetIP
    5.  
    6.     Shared Function GetIPAddress() As String
    7.       Dim oAddr As System.Net.IPAddress
    8.       Dim sAddr As String
    9.       With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
    10.          oAddr = New System.Net.IPAddress(.AddressList(0).Address)
    11.          sAddr = oAddr.ToString
    12.       End With
    13.       GetIPAddress = sAddr
    14.     End Function
    15.  
    16.     Shared Sub main()
    17.       Dim shostname As String
    18.       shostname = system.Net.DNS.GetHostName
    19.       console.writeline("Your Machine Name = " & shostname)
    20.       'Call Get IPAddress
    21.       console.writeline("Your IP = " & GetIPAddress)
    22.     End Sub
    23.  
    24.  End Class

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    This is the code I'm using currently:

    Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
    NewIP = ""
    NewIP = CType(h.AddressList.GetValue(0), System.Net.IPAddress).ToString

    Which only gives the NIC's IP address (192.168.0.1 or simular)... Is this code really different from your code? I know yours is much longer but it may be using the same class/members...

    Neofree

  10. #10
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Yes, its doing the same exact thing...

    And as you can tell, it can only figure out the address the router assigned to it... and that's all it will ever know, unless you connect to an external web server, and parse the data it returns to you ...aka ... showmyip.com

    If this isn't a production program, and only for your personal use, you can get away with connecting to an external web server... because they usually last at least a few years before someone closes the site because of bandwidth expenditures.

  11. #11
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    By the way, if you plan to implement an external web server... I would choose ftp://ftp.w3.org/pub/ and find a way to resolve your ip address from that server.

    It will probably be around for the next 10-15 years at least.

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    Does code already exist? Unfortunately static IP's are only sold in blocks by my ISP (Qwest.net) and it's just not worth what I'm trying to do.

    Thanks,

    Neofree

  13. #13
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Here's a link to a project that contains some code to get the ip address from showmyip.com:

    http://www.pscode.com/vb/scripts/Sho...txtCodeId=1468

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    Thanks!

    I've already implemented it into my code.. My project is just a small hobby program and if ShowMyIP.com falls off the earth, I'll just modify it to a different one, but no biggie.

    Neofree

  15. #15
    Lively Member
    Join Date
    May 2001
    Posts
    95
    I use Qwest as well and had the same issue. I switched to xmission and they gave me a static IP address for the same cost as having qwest as my ISP.

  16. #16
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Originally posted by sthomas
    I use Qwest as well and had the same issue. I switched to xmission and they gave me a static IP address for the same cost as having qwest as my ISP.
    (images of ralph from the simpson's enter my mind)

    'Children... where is your teacher' - Principal Skinner

    'I dress myself' - Ralph

    'Yes... very good Raplh' - Skinner
    Last edited by nemaroller; Aug 27th, 2003 at 08:14 PM.

  17. #17

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    I also am using Qwest. Although I know my ShowMyIP.com code now works fine, I discovered I need to configure port forwarding and cant get it to work for nothing. And Qwest doesnt support it! Guess I could go over to Earthlink.net or something, but Qwest provides the lines anyway.. Maybe they'd send me better equiment. This Actiontec gateway is actually kind of nice otherwise, can run 4 pc's off of it.

    Neofree

  18. #18
    Lively Member
    Join Date
    May 2001
    Posts
    95
    If you do not have a static IP address you are probably using DHCP. Actiontec router requires that it be 192.168.0.1. Your PC should have an IP address of say 192.168.0.3 If you go to say earthlink you can drop Qwest as the ISP. Earthlink would then assign you a static IP address. You would still use DHCP. However, like you said you would use port forewarding and reroute port 80 to your IP address of your server. This will work.

  19. #19

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    37
    I've done all this already.

    I am still with Qwest.

    1. I purchased a static IP.
    2. DHCP is configuring my box as 192.168.0.3
    3. I create port forwarding from MANY port ranges to 192.168.0.3
    4. I make sure I click Next and then save and restart.


    It never works. One thing the docs say is I can use port forwarding to forward port 80, so I even tried that port. And still it comes up with the configuration for the gateway on port 80 and yes I'm referencing by the static IP.

    Neofree

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width