Example

Fetch All IP Addresses

Author: Norman Deppenbroek
Return to REBOL Cookbook

Its very easy to display all the ip-addresses on your machine from within REBOL.

First create a block where you want to store the addresses:


    addresses: copy []

We will investigate the 'interfaces on the machine by using 'get-modes. The example below will return an object of all interfaces. In this example we used tcp-port 65432 and we dont need to open the tcp:// port first.


    >> probe get-modes tcp://:65432 'interfaces

Actualy, we want to have all the addresses of the 'interfaces ( addr ) inside the object, thus we create a 'foreach loop and store its result in our 'addresses block.


    foreach x (get-modes tcp://:65432 'interfaces) [append addresses x/addr]

Now the 'addresses contains something like:


    >> probe addresses
    == [127.0.0.1 192.168.168.1 10.10.10.1]

To print the result on screen you could use a simple


    forall addresses [print first addresses]

'get-modes can of course also be used on other 'ports beside tcp.


2006 REBOL Technologies REBOL.com REBOL.net