Categories: net

Obtain global IP in bash

In current Internet environment, every PC is assigned a private IP. If global IP is necessary, the router the PC is connecting has the IP. But accessing the router typically needs the password to access that should not appear on a bash script.

If you access http://checkip.dydns.com/, it returns the global IP, then the bash script to obtain global IP looks like the following.

ip=$(w3m -dump http://checkip.dyndns.com/ | grep -oP '\d+\.\d+\.\d+\.\d+')
  • w3m: text browser
  • -dump: shows the response and quit
  • -o: returns the matched text
  • -P: uses Perl regex
  • \d: represents a number
  • +: continuous number
  • \.: . itself
admin

Share
Published by
admin
Tags: baship

Recent Posts

Create log file in the directory of the script in Python

__file__ is the script file itself. From python3.9 above, it is an absolute path, otherwise…

3 years ago

RichTextBox’s font changes automatically in C#

You need to clear these two flags IMF_DUALFONT and IMF_AUTOFONT to keep font unchanged.

3 years ago

Test post to check image URL

This is an image inserted by wordpress 'Add Media'

3 years ago

msbuild says ‘target does not exist’

I don't know what is going wrong but... How to fix it Open the solution…

3 years ago

Creating a break point that hits on calling win32 api

Create a break point that hits when CreateProcess was called Enter a Function Breakpoint Enter…

4 years ago

Basic usage of unique_ptr and custom free of it

#include #include #include #pragma comment(lib, "Shell32.lib") using namespace std; class MyClass { public: MyClass() {…

5 years ago