Get IP Address

Z

Zikar

Hi
I was after a code that gets me the IP Address of the current machine and
found a link to the following source code previously referred by Graham R
Seach to someone called Lee and worked for him;
http://www.source-code.biz/snippets/vbasic/8.htm

I am finding difficulty in calling the value of the IP address to be
displayed in an unbound field in a form by using VB in Access 2003. Can
anybody help by providing me a very simple step by step instruction of how
this can be done? I would greatly appreciate the help. Thanks.

Regards
Zikar
 
D

Douglas J. Steele

The function returns more than one IP address. Which one do you want
displayed in the text box? For example, when I run the Test sub from that
page, I get:

Nr of IP addresses: 3
0.0.0.0
127.0.0.1
142.38.8.13

Presumably you'd want the last one of those. You'd have to create a function
along the lines of:

Public Function GetLastIPAddress()
Dim IpAddrs As Variant

IpAddrs = GetIpAddrTable()
GetLastIPAddress = IpAddrs(UBound(IpAddrs))

End Function

You'd then set the ControlSource of the unbound text box to

=GetLastIPAddress()

(be sure to include the equal sign and parentheses)
 
T

Tony Toews [MVP]

Douglas J. Steele said:
GetLastIPAddress = IpAddrs(UBound(IpAddrs))

And this only assumes the last IP address will always be the one you
want. Which one is the important one for my laptop which has both a
wired Ethernet connection, a wireless connection and a VPN connection
to my mail server as well as a few others.

0.0.0.0
10.3.0.3
127.0.0.1
192.168.53.100
192.168.53.101

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Z

Zikar

I thank you very much for the help. It finally worked! However, the procedure
gets the IP =127.0.0.1 while I am after a different IP that could most
probably be the last one. The procedure you suggested is getting the second
IP as per your tested output.

I did run the C:\WINDOWS\system32\cmd.exe function and executed the ipconfig
command. The IP address 127.0.0.1 did not appear among the printed output. I
also executed the arp -a command and obtained 7 output results but again non
did read IP 127.0.0.1, so I do not know what this output could be refering
to.

Is there anything else that can be done? I thank you by all means for the
help you provided.

Cheers
Zikar
 
Z

Zikar

Thanks Tony for the highlighted information. I am actually trying to get the
IP for a wireless connection. However, can you advise on how to filter out
each IP separately in multiple unbound fields, say n number of fields, given
the previous information? How can I know which is which (i.e. which is for
Ethernet, wireless, VPN etc.). Please note my earlier reply to Douglas as he
provided a valuable suggestion but I did not achieve yet what I am after. The
added information I provided him could help in understanding where I am
standing now. Thanks for your help.

Kind regards
Zikar
 
T

Tony Toews [MVP]

Zikar said:
Thanks Tony for the highlighted information. I am actually trying to get the
IP for a wireless connection. However, can you advise on how to filter out
each IP separately in multiple unbound fields, say n number of fields, given
the previous information? How can I know which is which (i.e. which is for
Ethernet, wireless, VPN etc.). Please note my earlier reply to Douglas as he
provided a valuable suggestion but I did not achieve yet what I am after. The
added information I provided him could help in understanding where I am
standing now.

We had this discussion once a while back with someone else. We
couldn't find an API call which would tell us the kind of connection
the IP address. We did however come up with the connection speed.
Given that wired is 10, 100 or 1000 mbps and wireless is 14 or 54 mbps
that was good enough for them.

I would poke about at vbnet.mvps.org and see what they have. Or it
might've been the WMI interface. I can't recall.

Tony

--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
Z

Zikar

Thanks for the advice. I will have to be satisfied with Douglas's solution.
However, I found that to get the IP for a wireless connection I need be
connected to it only and no other networks to be involved. I also found out
an explanation to what is the 127.0.0.1. The output reading 127.0.0.1 was
previously explained by “boblarson†as being simply the Loopback address of
the machine. It is nothing more than that and basically all PC based
computers have a loopback of 127.0.0.1.

Cheers
Zikar
 
Z

Zikar

Hi Douglas. Thanks for your help and I would have to be satisfied with what I
got from your proposed solution. Could you please clarify to me how did you
run the Test procedure in the emmidiate window?

Regards
Zikar
 
D

Douglas J. Steele

The sample code has two parts: a function called GetIpAddrTable and a sub
called Test that calls GetIpAddrTable.

I went to the Immediate Window (using Ctrl-G), typed Test and hit Enter.
 
Z

Zikar

I did follow this procedure before same as you did but still not working. I
am getting the error message Compile error: Sub or Function not defined. Is
there anything that I missed out in the code?

Thanks
Zikar
 
D

Douglas J. Steele

Well, the sample code is missing the End Sub for sub Test.

Where have you got the code? It needs to be in a stand-alone Module, not a
class module nor a module associated with a form or report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top