Code archives/Networking/Get PC's local IP address
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
Just a quickie that returns a string containing your PC's local (LAN) IP address, eg. mine returns "192.168.0.2". | |||||
Function LocalIP:String () Return DottedIP (HostIp ("", 0)) End Function Print LocalIP () |
Comments
| ||
Updated to handle erroneous result when non-localhost domains have been redirected to 127.0.0.1 via HOSTS file; thanks to _PJ_! |
| ||
Works on OSX 10.8.2 Returned my iMac/server IP address just fine. 192.168.1.100 |
| ||
James, Have you tried leaving the HostIP blank to default to the Local Machine? (Sorry B3d code, I HOPE it should still operate for BMax, similar commands at least... Function LocalIP$() n=CountHostIPs("") sIP$=HostIP(1) Return DottedIP(sIP) End Function Print LocalIP$() |
| ||
. |
| ||
Thanks, PJ -- I had to edit that a little bit, but this seems to work on my XP install:Function LocalIP:String () ip = HostIp ("", 0) Return DottedIP (ip) End Function Print LocalIP$() I'll try it on my Windows 7 setup later and update the code it if works. |
| ||
That works on my XP/Win7 PC and my separate Win7 PC, so updated main code. |
| ||
Good to know! :) |
Code Archives Forum