[bmx] Get PC's local IP address by BlitzSupport [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:43

Previous topic - Next topic

BlitzBot

Title : Get PC's local IP address
Author : BlitzSupport
Posted : 1+ years ago

Description : Just a quickie that returns a string containing your PC's local (LAN) IP address, eg. mine returns "192.168.0.2".

Code :
Code (blitzmax) Select
Function LocalIP:String ()
Return DottedIP (HostIp ("", 0))
End Function

Print LocalIP ()


Comments :


BlitzSupport(Posted 1+ years ago)

 Updated to handle erroneous result when non-localhost domains have been redirected to 127.0.0.1 via HOSTS file; thanks to _PJ_!


Captain Wicker (crazy hillbilly)(Posted 1+ years ago)

 Works on OSX 10.8.2Returned my iMac/server IP address just fine. 192.168.1.100


_PJ_(Posted 1+ years ago)

 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$()




_PJ_(Posted 1+ years ago)

 .


BlitzSupport(Posted 1+ years ago)

 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.


BlitzSupport(Posted 1+ years ago)

 That works on my XP/Win7 PC and my separate Win7 PC, so updated main code.


_PJ_(Posted 1+ years ago)

 Good to know! :) [/i]