This macOS application displays the current IP address of your computer in the menu bar. It alternates between displaying the WAN and LAN IP addresses every 3 seconds. Additionally, you can view both IP addresses in the menu and copy them to the clipboard by clicking on them. The app also includes options to launch at startup and quit the application.
- Displays the current IP address in the macOS menu bar.
- Alternates between WAN and LAN IP addresses every 3 seconds.
- Shows both WAN and LAN IP addresses in the menu.
- Allows copying the IP addresses to the clipboard by clicking on the menu items.
- Option to launch the app at startup.
- Option to quit the application.
- macOS 10.15 or later
- Xcode 12 or later
-
Clone the repository:
git clone https://github.com/ihugang/myip.git cd myip -
Open the project in Xcode:
open myip.xcodeproj
-
Build and run the project in Xcode.
Once the application is running, you will see an icon in the macOS menu bar displaying your current IP address. The IP address will alternate between WAN and LAN every 3 seconds.
Right-click on the icon to see the menu with the following options:
- WAN IP: Displays the WAN IP address. Click to copy the IP address to the clipboard.
- LAN IP: Displays the LAN IP address. Click to copy the IP address to the clipboard.
- Launch at Startup: Toggle the option to launch the application at startup.
- Quit: Quit the application.
The main logic of the application is implemented in the AppDelegate.swift file. Key functionalities include:
applicationDidFinishLaunching: Sets up the status item and menu, initializes the IP addresses, and starts the timer.toggleIPAddress: Alternates between displaying WAN and LAN IP addresses.checkAndUpdateIP: Checks for IP address changes and updates the display if necessary.getExternalIPAddress: Fetches the external IP address using thehttps://api.ipify.orgservice.getLocalIPAddress: Fetches the local IP address (IPv4 only).setupMenu: Sets up the menu items.updateMenu: Updates the menu with the current IP addresses.copyWanIPandcopyLanIP: Copies the respective IP addresses to the clipboard.toggleLaunchAtStartup: Toggles the option to launch the app at startup.quitApp: Quits the application.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.