|
-
Aug 26th, 2003, 09:31 AM
#1
Thread Starter
Member
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
-
Aug 26th, 2003, 09:56 AM
#2
I wonder how many charact
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.
-
Aug 26th, 2003, 10:15 AM
#3
Thread Starter
Member
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.
-
Aug 26th, 2003, 10:17 AM
#4
I wonder how many charact
Post the VB6 code API decleration
-
Aug 26th, 2003, 10:25 AM
#5
Thread Starter
Member
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
-
Aug 26th, 2003, 10:28 AM
#6
I wonder how many charact
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.
-
Aug 26th, 2003, 10:33 AM
#7
Thread Starter
Member
My configuration is:
PC -> NIC -> ActionTec DSL Gateway -> DSL Line/ISP
-
Aug 26th, 2003, 10:35 AM
#8
I wonder how many charact
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:
Option Strict Off
Imports system
Imports System.Net.DNS
Public Class GetIP
Shared Function GetIPAddress() As String
Dim oAddr As System.Net.IPAddress
Dim sAddr As String
With system.Net.DNS.GetHostByName(system.Net.DNS.GetHostName())
oAddr = New System.Net.IPAddress(.AddressList(0).Address)
sAddr = oAddr.ToString
End With
GetIPAddress = sAddr
End Function
Shared Sub main()
Dim shostname As String
shostname = system.Net.DNS.GetHostName
console.writeline("Your Machine Name = " & shostname)
'Call Get IPAddress
console.writeline("Your IP = " & GetIPAddress)
End Sub
End Class
-
Aug 26th, 2003, 10:40 AM
#9
Thread Starter
Member
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
-
Aug 26th, 2003, 10:42 AM
#10
I wonder how many charact
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.
-
Aug 26th, 2003, 10:49 AM
#11
I wonder how many charact
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.
-
Aug 26th, 2003, 11:03 AM
#12
Thread Starter
Member
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
-
Aug 26th, 2003, 11:06 AM
#13
I wonder how many charact
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
-
Aug 26th, 2003, 12:21 PM
#14
Thread Starter
Member
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
-
Aug 27th, 2003, 05:44 PM
#15
Lively Member
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.
-
Aug 27th, 2003, 08:09 PM
#16
I wonder how many charact
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.
-
Aug 28th, 2003, 11:12 AM
#17
Thread Starter
Member
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
-
Aug 28th, 2003, 11:28 AM
#18
Lively Member
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.
-
Aug 28th, 2003, 11:34 AM
#19
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|