Re: How do I get the IP address of an interface via applescript?
Re: How do I get the IP address of an interface via applescript?
- Subject: Re: How do I get the IP address of an interface via applescript?
- From: Ron Bishop <email@hidden>
- Date: Mon, 13 Oct 2003 08:40:40 -0500
Here's a script I had to quickly hobble together for a project. It uses
the ifconfig command to get the TCPIP address. Due to time constraints,
I used the free mgrep osax. You can modify it without the osax if
desired. Please post it if you do. Note, this is set to interface 0, if
you use an additional network card you'll need to change it (en1 or
whatever one you want to test) or add a test for additional
interfaces...
-------------------------------------------------
set the_ipconfig to do shell script "ifconfig en0 inet | grep -a \\d"
as string
set rawipaddress to mgrep the_ipconfig regex "\\d+[.]\\d+[.]\\d+[.]\\d+"
set AppleScript's text item delimiters to ""
--the following is one line
set the_ip_address to characters (matchPos of rawipaddress as number)
through ((matchPos of rawipaddress as number) + (matchLen of
rawipaddress as number)) of the_ipconfig as string
display dialog the_ip_address
-------------------------------------------------
Ron Bishop
Macintosh Systems Administrator
The Kansas City Star
1728 Grand Boulevard
Kansas City, MO 64108
816/234-4943
On Sunday, October 12, 2003, at 10:19 PM, Peter Schwenk wrote:
Hello:
I was trying to write a script that only tries to mount a network
share iff the network interface is on a particular subnet, but I've
been unable to get my script to find out what the IP address of an
interface is. The closest I've come is finding some discussion on
scripting the Apple System Profiler, but it didn't work as advertised.
I'm running Mac OS X 10.2.8 (applescript 1.9, i believe). Any
pointers would be gratefully appreciated.
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.