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
Printable View
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
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.
SmackAHobo i suggest being more helpful than that.
vb Code:
Private Sub Command1_Click() MsgBox Winsock1.LocalIP End Sub
:)
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.
Or you can google "Whats my ip"
=P
Hell Lord, he was asking what his internet IP is, not his local ip.
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'];
?>
Quote:
Originally Posted by SmackAHobo
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 mentionedQuote:
Originally Posted by Hell-Lord
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 routerQuote:
Originally Posted by sevenhalo
What part of what I said lead you to beleive I was suggesting to get it programatically?Quote:
Originally Posted by the182guy
The thread starter wanted to get it programatically.Quote:
Originally Posted by sevenhalo
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.Quote:
Originally Posted by dilettante
You can do it in one line with the Inet control, a few lines with winsock, and a lot more with the winsock API.
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.
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.Quote:
Originally Posted by the182guy
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. :)
Oh, and the VB code to 'unpack' the IP.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;
?>
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