Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Get your IP address
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="gatorparrots" data-source="post: 188"><p>If you are in a DHCP situation and find your IP address frequently changing, here is an easy way to determine it:</p><p><span style="color: blue">ipconfig getifaddr en0</span></p><p>and an alternate (albeit more convoluted method):</p><p><span style="color: blue">ifconfig en0 inet | grep 'inet ' | awk ' { print $2 } '</span></p><p></p><p>If you are behind a router and need your <strong>external</strong> IP address, issue this command:</p><p><span style="color: blue">wget -q -O /dev/stdout <a href="http://checkip.dyndns.org/" target="_blank">http://checkip.dyndns.org/</a> | grep 'Current IP Address: ' | awk ' { print $4 } '</span></p><p><em>(Of course, you would have to have <strong>wget</strong> installed in order for this to work.)</em></p><p></p><p>Here is a shell script for checking your IP address and logging the results to a file:[code]</p><p>#!/bin/sh</p><p>#initialize variable</p><p>IP=`wget -q -O /dev/stdout <a href='http://checkip.dyndns.org/' target='_blank'>http://checkip.dyndns.org/</a> | grep 'Current IP Address: ' | awk ' { print $4 } '`</p><p># prints current IP to shell</p><p>echo $IP</p><p>#log it</p><p>date >> /private/var/log/ip.log</p><p>echo $IP >> /private/var/log/ip.log[/code]</p><p>This script could be added to your crontab in order to check your IP address periodically and log the results to a file.</p></blockquote><p></p>
[QUOTE="gatorparrots, post: 188"] If you are in a DHCP situation and find your IP address frequently changing, here is an easy way to determine it: [color=blue]ipconfig getifaddr en0[/color] and an alternate (albeit more convoluted method): [color=blue]ifconfig en0 inet | grep 'inet ' | awk ' { print $2 } '[/color] If you are behind a router and need your [b]external[/b] IP address, issue this command: [color=blue]wget -q -O /dev/stdout [url=http://checkip.dyndns.org/]http://checkip.dyndns.org/[/url] | grep 'Current IP Address: ' | awk ' { print $4 } '[/color] [i](Of course, you would have to have [b]wget[/b] installed in order for this to work.)[/i] Here is a shell script for checking your IP address and logging the results to a file:[code] #!/bin/sh #initialize variable IP=`wget -q -O /dev/stdout <a href='http://checkip.dyndns.org/' target='_blank'>http://checkip.dyndns.org/</a> | grep 'Current IP Address: ' | awk ' { print $4 } '` # prints current IP to shell echo $IP #log it date >> /private/var/log/ip.log echo $IP >> /private/var/log/ip.log[/code] This script could be added to your crontab in order to check your IP address periodically and log the results to a file. [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Get your IP address
Top