6

I have the credentials for the Mac, but there is nobody in the room with the machine to check the public IP address.

enter image description here

If I know the public IP, I can connect to the mac. Unfortunately the ISP provides only dynamic IPs, so I guess it changed recently.

Is there any other way to gain access?

  • 2
    While not truly a technical solution, if that Mac is signed into any mail (Gmail for sure to my knowledge), any syncing solution, so forth, those services may provide a log that has your Mac's most recent IP. – Spotlight May 19 at 4:08
  • Is the machine logged in to iCloud/Apple services right now? Is it your account? – Harper May 19 at 16:25
  • @Harper well, I can see it as green in my apple account devices list. But couldn’t find any ip info. – Birowsky May 20 at 0:09
4

Ah! Yeah... your options at this point are limited. The ISP might help you as it's their DHCP that assigned the address; they'd be the only ones that would know that.

This has happened to me, and as my ISP is comcast, there is no help.

In the future :), what you need is "Dynamic DNS"; available free from several sources. I use FreeDNS. It's kind of funky, but seems to work reliably.

The other alternative (to dynamic DNS) is a "roll your own" approach that would require some script-writing on your part. If you're up for that, let me know & we'll go from there.

  • Thanx. I guess FreeDNS should be the way to go in the future. About rolling my own, do you mean publishing the ip on an interval, or something a bit more elaborate? – Birowsky May 18 at 14:24
  • @Birowsky: It could be more elaborate - depending on how far you want to take it. Since it's a Mac, you could have it run a script periodically to check its public IP address, compare it against the previous value, and use the Message app to text you if/when it changed. But of course you'll need access to your Mac to install that script. IMO, FreeDNS is easier, but the script is more, uh - educational? :) – Seamus May 18 at 16:14
2

The screen sharing service uses TCP port 5900. If indeed you have arranged so that you can connect to it if you only know the IP, that port should appear as open from outside.

Now, if you know what dynamic IP address it had before it changed, you can check WHOIS database to see the whole IP range that address belongs in. Chances are good that the new IP would belong to the same range, though that will depend totally on how your ISP allocates the addresses.

Now, after that, you could scan that whole subnet using e.g. nmap, looking for open port 5900. But before you do that, check on the legality of port scanning in whatever country you are currently in. In some countries it is legal if done without criminal intent, in other countries port scanning may be always illegal.

  • Love your out-of-the-box approach. How come you understand the legal repercussions here? What is your domain? – Birowsky May 19 at 8:33
  • 1
    @Birowsky Port scanning is not that rare when trouble-shooting all sorts of technical issues or trying to find devices on local network. It's good general knowledge to know the limits what one is allowed and not allowed to do, just like with lock picking or wifi sniffing. – jpa May 19 at 11:09
2

On the remote computer, save this following AppleScript code in a new Script Editor.App document (Script Editor.App is located here... /Applications/Utilities/Script Editor.app) as a "Stay Open" application. Before saving this document as an application, make sure you enter your current external IP address and the email address in the first two lines of the code.

To summarize what the AppleScript code does is simply... Every 15 minutes it checks your current external IP address against the IP address you set in the first line of the code. If those two IP addresses are not the same, the script will go ahead and send a new email (to the email address you set in the second line of the code) with the new updated external IP address.

Then just like opening any other application in Finder, double-clicking your newly created app will run the new app.

property ipAddress : "123.456.7.89" -- Insert Current External IP Address (Set Only Once)

property toRecipient : "whoever@gmail.com" --Email To Get IP Has Changed Messages

on idle
    set theIP to do shell script "curl ifconfig.co"

    if theIP is not equal to ipAddress then
        tell application "Mail"
            set newEmail to (make new outgoing message)
            set content of newEmail to theIP
            set subject of newEmail to "IP Address Has Changed"
            tell newEmail
                make new to recipient with properties {address:toRecipient}
                send
            end tell
        end tell
        set ipAddress to theIP
    end if

    return (15 * minutes) -- Waits 15 min. to check IP again
end idle

Don't forget to add this new AppleScript application, in System Preferences, to the list of apps allowed to control your computer.


UPDATE

Although the above script seems to work, after several runs and minor changes to the code for testing purposes, I decided to create an alternate solution. Because of the new security settings in macOS Mojave and AppleScript's inability to reliably update and maintain its Global and Persistent property values across runs, I feel this alternate solution is much more reliable.

Step 1: On the remote computer, in Script Editor.app, save this AppleScript code as a .scpt file and name it "Get Current External IP.scpt"

Be sure you change the value of property toRecipient to your email address

property ipAddress : "1.1.1.1" -- Not Necessary To Set
property toRecipient : "YourEmail@gmail.com" --Email To Get IP Has Changed Messages

set emailIsRunning to application "Mail" is running -- Checks If Mail Is Running

try
    set lastLoggedIP to readFile()
    set theIP to do shell script "curl ifconfig.co"
    if theIP is not equal to lastLoggedIP then
        sendNewEmail()
        writeToTheFile()
    end if
on error errMsg number errNum
    if errNum is -43 then -- The Error If File For readFile() Doesn't Exist Yet
        set theIP to do shell script "curl ifconfig.co"
        if theIP is not equal to ipAddress then
            sendNewEmail()
            writeToTheFile() -- Creates The "/private/tmp/IP Logger.txt" File
        end if
    else
        activate
        display dialog "An error has occurred:" & return & errMsg & " " & errNum giving up after 10
    end if
end try

delay 20 -- Allows For Completion Of Any Incoming Or Outgoing Mail Messages
if not emailIsRunning then quit application "Mail" -- Quits Mail If Wasn't Already Running

to sendNewEmail() -- Sends New Email Whenever IP Changes
    set theIP to do shell script "curl ifconfig.co"
    tell application "Mail"
        set newEmail to (make new outgoing message)
        set content of newEmail to theIP
        set subject of newEmail to "IP Address Has Changed"
        tell newEmail
            make new to recipient with properties {address:toRecipient}
            send
        end tell
    end tell
    set ipAddress to theIP
end sendNewEmail

on readFile() -- Reads IP Logger.txt To Check For IP Changes 
    set theFile1 to alias "private:tmp:IP Logger.txt"
    set lastLoggedIP to last item of (read theFile1 as text using delimiter linefeed)
end readFile

on writeToTheFile() -- Logs Every IP Change To File
    set theIP to do shell script "curl ifconfig.co"
    set theFile to "/private/tmp/IP Logger.txt"
    set theText to theIP
    try
        set writeToFile to open for access theFile with write permission
        write theText & linefeed to writeToFile as text starting at eof
        close access theFile
    on error errMsg number errNum
        close access theFile
        set writeToFile to open for access theFile with write permission
        write theText & linefeed to writeToFile as text starting at eof
        close access theFile
    end try
end writeToTheFile

Step 2: On the remote computer, in Script Editor.app, save this following AppleScript code as a "stay open" application file. I named it "IP Changed Email Notify.app".

If you did not save "Get Current External IP.scpt" to your Documents folder in Step 1 from above, then you must set its location in property currentExternalIP in the following code.

property currentExternalIP : alias ((path to documents folder as text) & "Get Current External IP.scpt")

run script currentExternalIP

on idle
    run script currentExternalIP
    return (15 * minutes)
end idle

The first time you run the new stay open AppleScript app (IP Changed Email Notify.app) from outside of Script Editor.app, you will be presented with this following dialog...

enter image description here

Just click "OK" and since all of the work is actually being done by "Get Current External IP.scpt" there should be no more future dialogs or alerts to deal with.

Step 3: (OPTIONAL) On the remote computer, add this newly created AppleScript application (IP Changed Email Notify.app) to your "Login Items" in the Users And Groups System Preferences panel. Now every time the computer restarts, IP Changed Email Notify.app will run automatically and any time the external IP address of that computer changes, you will get an email notification.

  • 1
    That's +1 cool... I woulda' used the Message app, but email works. A couple of other recommendations :) 1. post this a gist on GitHub, and 2. use the proper graphic for your handle wch1zpink. In closing, apologies for going off-topic, but could not resist :P – Seamus May 19 at 11:53
  • @Seamus, Regarding your comment "2. use the proper graphic for your handle wch1zpink", you have wrongly assumed that wch1zpink's picture has something to do with Pink Floyd. It does not! – user3439894 May 19 at 12:58
  • @user3439894: :) I'm sorry, and my apologies to wch1zpink. Good humor was really my intention. – Seamus May 19 at 13:06
  • @Seamus, I’m hoping some comments to Mark and I in the past few days weren’t intentionally condescending, as that’s how I’m seeing them. – user3439894 May 19 at 13:13
  • All in this comment thread - I’ve edited things and just want to remind everyone not to threaten anyone when moderation is needed and to keep the humor clearly pointed at oneself if anyone could think you are mocking or making fun of them. apple.stackexchange.com/conduct - I'll be in Ask Different Chat if people have questions or aren't clear on what I'm asking here. – bmike May 19 at 13:17
1

If the person on the other Mac is signed in with their Apple ID, you can simply start a iMessage session, click on the Details button and click on the Screen Sharing icon to start a screen sharing session.

enter image description here

You can both ask them to share their screen or invite to share your screen. This approach works seemlessly without needing an explicit IP address.

You'll need someone to be present physically near the machine to approve the screen sharing request though.

  • I'm the only one with an account on that remote machine : / – Birowsky May 18 at 14:04
  • @Birowsky Is the machine in the same local area network as your current machine? – Nimesh Neema May 18 at 14:07
  • Nope. Different country. – Birowsky May 18 at 14:16
  • @Birowsky you’ll need someone to be physically present to setup remote access (for once) before you get the ability to remotely access your machine. This could be done using any of myriad of remote access tools. – Nimesh Neema May 18 at 14:18
0

Probably not, especially if the Mac is behind a router, most of which block incoming connections.

In the future, I'd recommend using something like Screens or Jump Desktop which both have companion apps which will work around the various connection issues and allow you to connect remotely without needing to know the IP address.

  • If I know the public IP, I can connect to the mac. Unfortunately the ISP provides only dynamic IPs, so I guess it changed recently. Does knowing that the router is configured properly change anything? (thanx for the suggestions) – Birowsky May 18 at 13:57
  • "If you know the public IP" is the whole trick, indeed. but unless you have something set up in advance, there's no way practical to figure out the IP now, regardless of how the router is set up. – TJ Luoma May 18 at 18:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .