Does anyone know how to get the IP address of a selected file in Finder? I have a snippet here that collects other information successfully. The problem comes when we have Windows sharepoint using the smb:// protocol. No server name pops up, and I could benefit from getting the IP address.
I have included what I have below for reference.
tell application "Finder"
set theFile to item 1 of (get selection) as text
end tell
tell application "System Events"
set volumeName to volume of file theFile
set serverName to server of disk volumeName
end tell
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)
Maybe you can send a DNS Query? You’ll find it if you google it!
But you have to get the smb name from somewhere first of course, to make it make sense!
you’ll find something in a mounted finder window, under URL of container 1 of containers of container of target of finder window 1, when the mounted window is the frontmost, at least when it is an ftp, I don’t use smb.
But you should be able to get the hostaddress, as it pops up in the sidebar of the finder. I only get the disk name of the shared volume with the properties above.
This isn’t much useful. I think you have to find a way to look at your connections, and when you find the host of the smb connection, then you can query the DNS Server for the ip address.
I also went into System Events, under Network Domain, but I couldn’t find anything usable there either, and nothing more under disks of System Events. All you get is the mounted volume name really.
When the guy passes buy, who knows the incantation to list your open ftp connections.
I have tried lsof -i and netstat -A inet --program without getting to be any wiser.
It seems like a complex solution but when a disk’s node (mount point) is outside the ‘Voumes’ folder this script still works.
tell application "Finder"
set theFile to POSIX path of (item 1 of (get selection) as text)
end tell
tell application "System Events"
set volumeName to volume of disk item theFile
set serverName to server of disk volumeName
end tell
if serverName = missing value then --then check for smb volumes
set smbVolumes to every paragraph of (do shell script "mount -t smbfs | awk '{print \"smb:\" $1 \" \" $3}' ")
set AppleScript's text item delimiters to tab
repeat with anItem in smbVolumes
set {_url, _node} to every text item of anItem
if theFile begins with _node then
set serverName to do shell script "/bin/echo -n " & quoted form of _url & " | php -r '$x = parse_url(fgets(STDIN));echo $x[\"host\"];'"
exit repeat
end if
end repeat
set AppleScript's text item delimiters to ""
end if
return serverName
Stealing DJ Bazzie Wazzie’s concept,I made one, not so stable really,( but it works for me), for getting the ip-address of an ftp server, by selecting a file on the mounted ftp-volume.
tell application "Finder"
set theFile to POSIX path of (item 1 of (get selection) as text)
end tell
tell application "System Events"
set volumeName to volume of disk item theFile
end tell
set ftpVolumes to first paragraph of (do shell script "mount | grep " & volumeName) as text
set AppleScript's text item delimiters to "//"
set ftpAddr to text items of ftpVolumes
set ftpAddr to text item 2 of ftpAddr as text
set AppleScript's text item delimiters to ""
set ipaddr to first paragraph of (do shell script "ping -c 1 " & ftpAddr) as text
set AppleScript's text item delimiters to {"(", ")"}
set ipaddr to text items of ipaddr
set ipaddr to text item 2 of ipaddr as text
set AppleScript's text item delimiters to ""
return ipaddr
That’s normal because it’s hard to get this stable. First because there is originally no such thing as an FTP file system and because of that there are many different, non-standardized, solutions to create a FTP file system.
The best we know is FTPfs which is used by the Finder (which uses mount_ftp) and is a read only FTP file system. It uses NFS protocol with a binding to create this and even if the manual page says that read-only mode is a bug (it’s written in the bug section) it’s a feature since Mac OS X 10.2. Mount will show this volume as an NFS volume.
Another alternative (which I use) is using curlFTPfs which makes use of FUSE (Filesystem in USErspace) and libcurl to mount an FTP server as a file system with read and write access. But the following things happens when you’re using an 3rd party virtual file system.
Volume is an fusefs volume and not an NFS volume like Mac OS X’s built-in FTPfs.
Also finder path notation to string coercion isn’t correct and also posix path fails as well. (there are workarounds)
The shell’s mount command can’t give you information about the server.
diskutil (shell or application) doesn’t support these file systems; doesn’t provide any information.
System Events gives missing value for server but also NFS format for file system format.
What I found particularily unstable with the solution above, was the usage of ping to get the ip-address, and that was an idea of my own!
Your reality may be a stable network, mine is not, as I move through wifi and hotspots during the day, with different loads on them. That may make the ping command take some time. Apart from that, and that I don’t know if I get the correct ftp-address if I have several almost identical disks mounted, (also a defect of my own), I think the script is good.