Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > IP address

IP address
Thread Tools
l008com
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
Mar 16, 2000, 01:47 AM
 
I'm sure this one gets asked alot...
How can i referance my IP address via an AppleScript? Can i do it 'stock' or do i need and special scripting additions or other scriptable programs?

------------------
I hate Microsoft!
All hail Apple!
Steve Jobs knows best!
     
MacCanada
Junior Member
Join Date: Oct 1999
Location: Edmonton, Alberta, Canada
Status: Offline
Reply With Quote
Mar 17, 2000, 11:05 PM
 
here's one using a non stock osax:

Network Info

the code for that is a one liner:
get IP address of (get network information)


if you wanted to email your IP to someone, use the Sendmail OSAX sample code for that:

<applescript code>

global g_IP
-- makes g_IP global to the whole script

property p_From : "Your Mac <[email protected]>"
-- sets the FROM header the adress must be enclosed by angle brackets <>

property p_To : " Your Other Address <[email protected]>"
-- sets the TO header the adress must be enclosed by angle brackets <>

property p_Sub : ""
-- sets the SUBJECT

property p_Sig : ""
-- sets a signature if you want one

property p_messageBody : ""
-- the message body

property p_mailserver : "smtp.telusplanet.net"
-- your mail server (where the mail gets sent through)

property p_miscHeaders : "x-mailer: AppleScript with sendmail v.1.0
x-URL: http://www.apple.com/applescript/
Content-Type: text/plain; charset=us-ascii
" -- sets some headers, for X-mailer (identifying the mail client, x-url for the mail client's url, and the content type of the mail

set g_IP to (get IP address of (get network information) as text)
-- gets the mac's IP address, this needs the NetworkInfo OSAX

set p_mishHeoaders to p_miscHeaders & "x-ip-address:" & g_IP & "
" -- appends a x-ip-address header to the headers

set p_Sub to p_Sub & g_IP as text
-- appends the actual IP to the subject

set p_messageBody to g_IP as text
-- sets the message body


send email "From: " & p_From & return & "To: " & p_To & return & "Subject: " & p_Sub & return & p_miscHeaders & "x-ip-address: " & g_IP & return & p_messageBody & p_Sig via p_mailserver
-- sends the email

</applescript code>

hope this helps


------------------
PGP key: http://www.geocities.com/maccanada/pgpkey.html
-30-
-- An idea is salvation by imagination.
-- Frank Lloyd Wright
-- 30 --
     
numero
Junior Member
Join Date: Mar 2000
Location: Salem, OR, USA
Status: Offline
Reply With Quote
Mar 18, 2000, 02:17 AM
 
Originally posted by l008com:
I'm sure this one gets asked alot...
How can i referance my IP address via an AppleScript? Can i do it 'stock' or do i need and special scripting additions or other scriptable programs?


No special scripting additions or OSAXen needed.

********

tell application "Network Setup Scripting"
try
open database
begin transaction
set ipa to IP address of every TCPIP v4 configuration whose active is true
end transaction
close database
on error
abort transaction
close database
end try
end tell
display dialog (ipa as string)

********

Credit is due to:
Jeff Baumann
[email protected] www.linkedresources.com


I poked around a little on this one, but there is *NO* docs on Network Setup addition. Once I saw this snippet on the applescript list it all became clear.

-numero
     
MacCanada
Junior Member
Join Date: Oct 1999
Location: Edmonton, Alberta, Canada
Status: Offline
Reply With Quote
Mar 18, 2000, 04:49 AM
 
i have found tht that only works ( for me at least) if the configuration has a manually entered IP address,

so anyone that uses Dial up or broadband connections (Cable, DSL, etc) are sol...

it would just return 0.0.0.0

not very useful...




------------------
PGP key: http://www.geocities.com/maccanada/pgpkey.html
-30-
-- An idea is salvation by imagination.
-- Frank Lloyd Wright
-- 30 --
     
l008com  (op)
Addicted to MacNN
Join Date: Jan 2000
Location: Stoneham, MA, USA
Status: Offline
Reply With Quote
May 8, 2000, 08:56 PM
 
Yeah, i just got 0.0.0.0 too!
Is there s simple scripting addition that simply tells you your IP and that's it?

------------------
I see dead people.
     
Paul Crawford
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
May 9, 2000, 02:51 AM
 
Hi again,

If you don't wish to use the Network Info OSAX mentioned above by MacCanada (in the 2nd post in this thread), you could try searching for alternative OSAXen via the usual suspects such as ScriptWeb's Osaxen scripting-additions library or the AppleScript Sourcebook's Scripting Additions, Add-Ons & Plug-Ins links page.

Regards,

--Paul
     
Chris O'Haver
Guest
Status:
Reply With Quote
May 9, 2000, 11:08 AM
 
Use Apple System Profiler...

tell application "Apple System Profiler" to TCPIPAddress


For some strange reason, AppleScript wanted to cooerce the "TCPIPAddress" into "TCPIPGateway" ... for an even stranger reason, it worked anyway. (but I can't get it to report the gateway...)
     
numero
Junior Member
Join Date: Mar 2000
Location: Salem, OR, USA
Status: Offline
Reply With Quote
Jun 17, 2000, 03:45 AM
 
Here is one way to do it "stock" without any special OSAX

* * * begin code * * *

(*
Script parses the Apple System Profiler info for the IP address of the machine.
I don't have a DHCP setup to test this on, but it should solve the problems
people are having with scripting OT.

Let me know if you have any problems.
[email protected]
*)

set myTempFile to (((path to startup disk) as string) & "reportfile.txt")


tell application "Apple System Profiler"
activate
set reportName to make new report at beginning with properties {report view format:"text", report contents:{system profile}}
save reportName in file myTempFile
close saving no
end tell

set reportFile to open for access file myTempFile
set foundIP to false
repeat until foundIP
set aLine to read reportFile until return
if aLine contains "IP address" then
set foundIP to true
end if
end repeat

set AppleScript's text item delimiters to ":"
set ipAddress to text item -1 of aLine
close access reportFile

tell application "Finder"
move alias myTempFile to trash
-- empty trash without warning
end tell
display dialog ipAddress

* * * end code * * *


     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 11:22 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,