|
-
May 15th, 2007, 07:50 AM
#1
Thread Starter
Fanatic Member
What is my IP address?
Dear Friends,
How to get the IP address of my computer when I am connected to the internet?
Please let me know the vb6 code to get the IP address.
Regards,
vblearner6
-
May 15th, 2007, 09:35 AM
#2
Lively Member
Re: What is my IP address?
Dude u really need to look this **** up before asking such basic questions that have been covered so many times. Head on over to PSC, there u will find so many different variations of that sort of **** its like a network programmers wet dream.
-
May 15th, 2007, 10:56 PM
#3
Re: What is my IP address?
SmackAHobo i suggest being more helpful than that.
vb Code:
Private Sub Command1_Click()
MsgBox Winsock1.LocalIP
End Sub
-
May 15th, 2007, 11:00 PM
#4
Re: What is my IP address?
Yours, on your network; you can find with a simple command promp and typing "ipconfig"
(assuming you have a router) If you need to find the IP of your gateway, log into your router:
typically: http://192.168.1.1
and if you use a linksys, it's admin for the user and admin for the password.
And look up you specs in there.
-
May 15th, 2007, 11:20 PM
#5
Member
Re: What is my IP address?
Or you can google "Whats my ip"
=P
-
May 15th, 2007, 11:44 PM
#6
Re: What is my IP address?
-
May 16th, 2007, 02:06 AM
#7
Lively Member
Re: What is my IP address?
Hell Lord, he was asking what his internet IP is, not his local ip.
-
May 16th, 2007, 03:53 AM
#8
Re: What is my IP address?
The .LocalIP will work if they are not behind a router/on a network.
Otherwise, you'll have to use a remote server like iPrank posted.
Or write your own PHP script and put it on a server that supports PHP. The simplest way would be:
PHP Code:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>
-
May 16th, 2007, 04:47 AM
#9
Re: What is my IP address?
 Originally Posted by SmackAHobo
Hell Lord, he was asking what his internet IP is, not his local ip.
He asked for his IP when an internet connection is made. And that code will get him his localIP which is it. If there is no connection it will give him 127.0.0.1 obviously. And if he has established an internet connection then it will give him his IP
-
May 16th, 2007, 09:39 AM
#10
Re: What is my IP address?
 Originally Posted by Hell-Lord
He asked for his IP when an internet connection is made. And that code will get him his localIP which is it. If there is no connection it will give him 127.0.0.1 obviously. And if he has established an internet connection then it will give him his IP 
When on a network LocalIP is not the same as Internet IP. Most people use routers these days, so will need to contact an external service such as iPrank and DigiRev mentioned
-
May 16th, 2007, 10:01 AM
#11
Re: What is my IP address?
No, no you don't need to use an external site. You can and thats fine and dandy, but you can get the information from your router on what your gateway's IP is. If you don't have a static one, it'll change 3 or 4 times a week, but you can still get it without assistance.
Not to mention, some ISPs will proxy; meaning - you can't find your own IP address through those kinds of sites. You make a request and then they "peel the packet" and remake the request for you. It helps cut down on upload traffic and also gives them a quick, single spot way of determining if that site is attempting to do something malicious in response to your request. ISPs don't promise protection (liability reasons), but they do protect to some degree.
-
May 16th, 2007, 10:45 AM
#12
Re: What is my IP address?
 Originally Posted by sevenhalo
No, no you don't need to use an external site. You can and thats fine and dandy, but you can get the information from your router on what your gateway's IP is. If you don't have a static one, it'll change 3 or 4 times a week, but you can still get it without assistance.
Not to mention, some ISPs will proxy; meaning - you can't find your own IP address through those kinds of sites. You make a request and then they "peel the packet" and remake the request for you. It helps cut down on upload traffic and also gives them a quick, single spot way of determining if that site is attempting to do something malicious in response to your request. ISPs don't promise protection (liability reasons), but they do protect to some degree.
It's easier to get it from a site such as provided than to try and programatically get it from the router
-
May 16th, 2007, 10:52 AM
#13
Re: What is my IP address?
 Originally Posted by the182guy
It's easier to get it from a site such as provided than to try and programatically get it from the router
What part of what I said lead you to beleive I was suggesting to get it programatically?
-
May 16th, 2007, 02:47 PM
#14
Re: What is my IP address?
 Originally Posted by sevenhalo
What part of what I said lead you to beleive I was suggesting to get it programatically?
The thread starter wanted to get it programatically.
-
May 16th, 2007, 05:22 PM
#15
Re: What is my IP address?
Here is a demo that does it programmatically both ways. I hope it doesn't drive anyone batty trying to make sense of the code.
Short answer: an external web site is much easier, much less code. Though you need to hard-code an external URL and tailored parsing logic you only need to do it once.
Asking the NAT router is not only a lot of work but you need a URL (or at least a page) hard coded along with parsing logic for every different router. It's more work because you have to discover the NAT router to ask it... unless you do hard-code the entire URL.
Of course the URLs and parsing "bracket" strings can be parameterized fairly simply. The demo shows this clearly. Note that the "ask your NAT" part of the demo won't work unless you insert values that fit your own router into the demo form. Otherwise it will return the Local IP marked as "questionable."
Last edited by dilettante; May 16th, 2007 at 05:25 PM.
-
May 17th, 2007, 03:17 AM
#16
Re: What is my IP address?
 Originally Posted by dilettante
Here is a demo that does it programmatically both ways. I hope it doesn't drive anyone batty trying to make sense of the code.
Short answer: an external web site is much easier, much less code. Though you need to hard-code an external URL and tailored parsing logic you only need to do it once.
Asking the NAT router is not only a lot of work but you need a URL (or at least a page) hard coded along with parsing logic for every different router. It's more work because you have to discover the NAT router to ask it... unless you do hard-code the entire URL.
Of course the URLs and parsing "bracket" strings can be parameterized fairly simply. The demo shows this clearly. Note that the "ask your NAT" part of the demo won't work unless you insert values that fit your own router into the demo form. Otherwise it will return the Local IP marked as "questionable."
Exactly, it's completely insane to try and get it from the router's control panel when every manufacturer is different, and to make it even harder, a lot of them require authentication before giving you access to the IP.
You can do it in one line with the Inet control, a few lines with winsock, and a lot more with the winsock API.
-
May 17th, 2007, 03:27 AM
#17
Re: What is my IP address?
I tried fussing with my router to see if I could make a version more "portable" (i.e. handle any UPnP router) but I never got very far. The UPnP approach wasn't very practical, and at best required several requests of the router via HTTP.
AS far as I know most home routers can return the required info without a logon though, via an HTML status page. Usually this is the default page.
-
May 17th, 2007, 12:11 PM
#18
Re: What is my IP address?
Well the most professional way that will support all routers is to have a server-side script running on a webhost, have the script require a password so nobody else can use it. The script will return the IP when executed and authenticated.
You can get a basic PHP host for about £3 per month.
I wouldn't use whatismyip.org in a professional or commercial app because its obviously an external party and they could be doing anything with the IP's they return.
-
May 17th, 2007, 03:53 PM
#19
Re: What is my IP address?
 Originally Posted by the182guy
Well the most professional way that will support all routers is to have a server-side script running on a webhost, have the script require a password so nobody else can use it. The script will return the IP when executed and authenticated.
You can get a basic PHP host for about £3 per month.
I wouldn't use whatismyip.org in a professional or commercial app because its obviously an external party and they could be doing anything with the IP's they return.
Yea I'd definitely not rely on any other sites for getting an IP address when it comes to professional apps. If you're selling a commercial app, then you should put the script on your website and use that.
Then you just need to make sure your site doesn't go down.
To save bandwidth/prevent everyone from using your script to get their IPs you can also compress the IP into 4 bytes.
Chr$(Octect1) & Chr$(Octect2) & Chr$(Octect3) & Chr$(Octect4)
Then just ASC the compressed 4 bytes back into an IP
Asc(C1) & "." & Asc(C2) etc...
This is how I did mine: www.dannydotguitar.com/ip.php
Here's the source to the PHP script, not sure if anyone will find it useful, but whatever. 
PHP Code:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$oct = explode('.', $ip);
$pack_ip = chr($oct[0]) . chr($oct[1]) . chr($oct[2]) . chr($oct[3]);
echo $pack_ip;
?>
Oh, and the VB code to 'unpack' the IP.
vb Code:
Private Sub Command1_Click()
Dim strData As String, strIP As String
strData = Inet1.OpenURL("http://www.dannydotguitar.com/ip.php")
If Len(strData) = 4 Then
strIP = Asc(Left$(strData, 1)) & "." & _
Asc(Mid$(strData, 2, 1)) & "." & _
Asc(Mid$(strData, 3, 1)) & "." & _
Asc(Right$(strData, 1))
End If
End Sub
Last edited by DigiRev; May 17th, 2007 at 03:57 PM.
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
|