Solved

Winsock - Get LocalIP for Internet and not LAN

Posted on 2004-10-20
11
298 Views
Last Modified: 2013-11-13
When i call Winsock1.LocalIP it returns the ip address of my computer's ethernet card (10.0.0.1) even though im connected to the internet.

How do i get my computers internet ip address using winsock control or any api function - NOT another Control (dont want too many dependencies) ?

How would I know which is the internet IP address.
0
Comment
Question by:kurian2z5
11 Comments
 
LVL 4

Author Comment

by:kurian2z5
ID: 12360303
i would prefer to use the winsock control
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12360572
what do you get form ipconfig /all
0
 
LVL 4

Author Comment

by:kurian2z5
ID: 12365290
Ethernet Adapter 0 is my internet connection and it shows my internet ip address.
Ethernet Adapter 1 is my Lan card and it shows my Lan ip address.

I need it done automatically so that my program is automated. How does it know which is the internet IP address.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12365810
"This article illustrates how to programmatically retrieve IP configuration information similar to the IPCONFIG.EXE utility. It demonstrates how to use the IP Helper APIs GetNetworkParams() and GetAdaptersInfo() from Visual Basic."

http://support.microsoft.com/default.aspx?scid=kb;en-us;223025
0
 
LVL 4

Author Comment

by:kurian2z5
ID: 12366609
this is really compicated and i dont want all this code in my program. More over how will I know which is the Internet IP address other than the fact that it is usually a PPP adapter.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:kurian2z5
ID: 12366612
is there any way to do this using the winsock control ?
0
 
LVL 2

Expert Comment

by:koolnurd
ID: 12366616
The client's applications creates socket and assigns to him the random number of TCP/IP port it will work with. But it does not happen at the server machine. The server applications, as a rule, work with the early-defined TCP/IP ports. For example, the number of TCP/IP port for FTP server is 21, and another one for Web server is 80. There is a "global arrangement" for widely used services. It defines the number of ports the clients could send their requests by default.

Protocol Port Description
SMTP    25    Simple Mail Transfer Protocol  
POP3    110    Post Office Protocol
NNTP    119    Network News Transfer Protocol
FTP      21       File Transfer Protocol
HTTP    80       Hyper Text Transfer Protocol  


The client starts the network sessions with server via one of the network protocols. The client creates socket and forces it to connect to the remote server. The socket gets the address of server and the number of port to which it has to connect to. As for Winsock control then you should invoke the Connect method. Look at the example below. It shows how to connect to FTP server.

Winsock1.Connect "ftp.microsoft.com", 21

0
 
LVL 4

Author Comment

by:kurian2z5
ID: 12366632
how do i get the Internet IP address of my computer instead of the Lan ip address using this ?
0
 
LVL 4

Author Comment

by:kurian2z5
ID: 12366655
I found out how to get the Internet IP using the winsock control.

When you just create a winsock control, the LocalIP property returns the Lan ip address of the computer.

But when you connect to any other computer on the internet using that same winsock control , LocalIP returns the IP address of the adapter through which it connected.

Private Sub Form_Load()

MsgBox Winsock1.LocalIP 'returns Lan IP address
Winsock1.RemoteHost = "experts-exchange.com"
Winsock1.RemotePort = 80
Winsock1.Connect

End Sub

Private Sub Winsock1_Connect()

MsgBox Winsock1.LocalIP 'returns Internet IP address

End Sub
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12405448
Question answered by asker or dialog valuable.
Closed, 50 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordmultiple challenge 12 121
How to debug this code 7 56
base64 decode encode 12 122
converting visio 2010 to powerpoint 2010  - formatting issues 5 41
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now