Lisp HUG Maillist Archive

Getting IP address

This seems like it should be a trivial question:

How do I get the IP address of my computer through LispWorks?

I've looked through the COMM package documentation and don't see it. In case it matters, I'm using LW 6.0.1 (Intel) on Mac OS X v. 10.6.8.

Thanks as always,
LW

Re: Getting IP address

Wow, more trivial than I realized. This is a server application where I will almost certainly want to assign a static address, although you're welcome to enlighten me further if I'm mistaken about that.

LW

On Jan 21, 2012, at 4:36 PM, Laughing Water wrote:

> 
> This seems like it should be a trivial question:
> 
> How do I get the IP address of my computer through LispWorks?
> 
> I've looked through the COMM package documentation and don't see it. In case it matters, I'm using LW 6.0.1 (Intel) on Mac OS X v. 10.6.8.
> 
> Thanks as always,
> LW


Re: Getting IP address

Try something like this.

(require "comm")
(setf IpInt (comm:get-host-entry "YourPcName" :fields '(:address)))
(setf IpList '())

(loop for n in '(16777216 65536 256 1) do
       (setf IpList (append IpList (list (floor (float (/ ipint n)))))
             ipint (- ipint (* (floor (float (/ ipint n))) n))))

If you want more IP's like for multi-homed nic uses "addresses" keyword in  
the get-host-entry call to get a list.

IpList = (10 0 0 3)

-- 
Regards,

William P. Proffitt


Updated at: 2020-12-10 08:37 UTC