[Gambas-user] Obtain my IP with Gambas

Steven James Drinnan steven at ...2097...
Thu Sep 10 07:00:22 CEST 2009


Sorry here is a revised one with a wan IP lookup

DIM mycmd AS String
DIM myIP AS String
DIM myWanIP AS String

'returns the ip of a particular device replace eth0 with the name of the
device
mycmd = "ifconfig eth0| grep -w 'inet addr'| cut -d: -f2| awk '{print
$1}'"
'mycmd = "ifconfig| grep -w 'inet addr' | grep -v '127.0.0.1' | cut -d:
-f2| awk '{print $1}'"
SHELL mycmd TO myIP
PRINT myip

'You need wget to get this from the internet.
'mycmd = "wget www.whatismyip.com/automation/n09230945.asp -O - -q"
'using whatismyip
mycmd = "wget www.sjdsoft.hk/getip.php -O - -q" 'using my webserver
(seems faster based in Hong Kong)


SHELL mycmd TO myWanIP
PRINT myWanIP

On Thu, 2009-09-10 at 11:20 +0800, Steven James Drinnan wrote:

> You could try this
> 
> DIM mycmd AS String
> DIM myIP AS String
> 
> 
> mycmd = "ifconfig| grep -w 'inet addr' | grep -v '127.0.0.1' | cut -d:
> -f2| awk '{print $1}'"
> 
> SHELL mycmd TO myip
> 
> PRINT myip
> 
> Have not confirmed what it returns but by the looks it returns the local
> assigned ip. Not the wan side.
> 
> 
> On Wed, 2009-09-09 at 19:12 +0200, Jean-Yves F. Barbier wrote:
> > Benoît Minisini a écrit :
> > >> On Wednesday 09 September 2009, Benoît Minisini wrote:
> > >>>> mmmm it's OK, I think there must be something like User.IP :)
> > >>>>
> > >>>>  Regards
> > >>>>
> > >>>>
> > >>>> --
> > >>>> David
> > >>> The IP address is not related to the user at all.
> > >> How about System.IP?
> > >>
> > >>
> > >> However David Villalobos did not tell which IP he wants.
> > >> I do have a IP at the incomming connection of my building.
> > >> For me known as WAN and a IP at the box, known to me as LAN.
> > >>
> > >> http://www.myipaddress.com for your WAN IP address :)
> > >>
> > >> Best regards,
> > >>
> > >> Ron_1st
> > >>
> > > 
> > > IP address are attached to network interfaces, and I'm not sure that a network 
> > > interface could not have several IP, and different types of IPs.
> > 
> > yep, that's right. 
> > ie: you can easily attach multiple IP adresses to an Ethernet interface as aliases,
> >     thus having one ethernet HW I/F that have 10 different IP addresses.
> >  
> > > Instead of adding thousands lines of code to the interpreter, I think the 
> > > better is parsing the output of the ifconfig command.
> >  
> > that's right too, many programs/scripts return different strings, obliging
> > the dev to consider each possible return
> > 
> > JY
> 
> 
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with 
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user



More information about the User mailing list