Use the Shell command line to obtain the local IP address
Use the Shell command line to obtain the local IP address
Enter ifconfig
under mac or enter# under linux
##ip a can get our network card information. But usually, what we need to check is our IP address, and we don't need so much information. So, I want to extract this information.
ifconfig and we will get a large piece of information. We can see that the string in front of the IP address we want is
inet
ifconfig | grep inet
inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 inet6 fe80::85e:9798:4041:1717%en0 prefixlen 64 secured scopeid 0x4 inet 192.168.12.139 netmask 0xffffff00 broadcast 192.168.12.255 inet6 fd86:415c:c5f9::c72:1c02:f044:65de prefixlen 64 autoconf secured inet6 fd86:415c:c5f9::cd76:7bb1:f77d:46f0 prefixlen 64 deprecated autoconf temporary inet6 fd86:415c:c5f9::508d:685b:6a66:b3ce prefixlen 64 autoconf temporary inet6 fe80::9446:a1ff:fe5e:9b8f%awdl0 prefixlen 64 scopeid 0x9 inet6 fe80::9d71:6fa:3da5:9cb6%utun0 prefixlen 64 scopeid 0xa
inet6 and
127
ifconfig | grep inet | grep -v inet6 | grep -v 127
inet 192.168.12.139 netmask 0xffffff00 broadcast 192.168.12.255
ifconfig | grep inet | grep -v inet6 | grep -v 127 | cut -d ' ' -f2
getip file under
~/.bin/ and use
chmod +x ~/.bin/getip to execute it permissions. Then enter
getip in the command line to get our local IP.
You need to configureImplement the script to obtain the local IP under linux centos 7~/.bin/
as an environment variable first. Please refer to this command as a system command, which can be executed at any time
linux Do not use the
ifconfig command to obtain information, but use
ip a to obtain.
ip a | grep inet | grep -v inet6 | grep -v 127 | sed 's/^[ \t]*//g' | cut -d ' ' -f2
sed ' s/^[ \t]*//g' to remove leading spaces.
The above is the detailed content of Use the Shell command line to obtain the local IP address. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
![Explorer.exe does not start on system startup [Fix]](https://img.php.cn/upload/article/000/887/227/168575230155539.png?x-oss-process=image/resize,m_fill,h_207,w_330)
Nowadays, many Windows users start encountering severe Windows system problems. The problem is that Explorer.exe cannot start after the system is loaded, and users cannot open files or folders. Although, Windows users can open Windows Explorer manually using Command Prompt in some cases and this must be done every time the system restarts or after system startup. This can be problematic and is due to the following factors mentioned below. Corrupted system files. Enable fast startup settings. Outdated or problematic display drivers. Changes were made to some services in the system. Modified registry file. Keeping all the above factors in mind, we have come up with some that will surely help the users

When processing files under Linux systems, it is sometimes necessary to delete lines at the end of the file. This operation is very common in practical applications and can be achieved through some simple commands. This article will introduce the steps to quickly delete the line at the end of the file in Linux system, and provide specific code examples. Step 1: Check the last line of the file. Before performing the deletion operation, you first need to confirm which line is the last line of the file. You can use the tail command to view the last line of the file. The specific command is as follows: tail-n1filena

Many friends who use win10 system have encountered this problem when playing games or installing the system. The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. This may be because the operating system does not have corresponding permissions. Let’s take a look at the specific tutorial below. Tutorial on using the command line sxstrace.exe tool 1. This problem usually occurs when installing programs and games. The prompt is: The application cannot be started because the parallel configuration of the application is incorrect. For more information, see the application event log, or use the command line sxstrace.exe tool. 2. Start →

This article details the steps to upgrade Ubuntu 20.04 to 22.04. For users using Ubuntu 20.04, they have missed the new features and advantages brought by version 22.04. In order to get a better experience and security, it is recommended to upgrade to a newer Ubuntu version in time. Ubuntu22.04 is codenamed "Jamie Jellyfish", let's explore how to get the latest LTS version! How to upgrade Ubuntu 20.04 to 22.04 via the command line Mastering the command line will give you an advantage. While it is possible to update Ubuntu via the GUI, our focus will be via the command line. First, let’s check the currently running version of Ubuntu using the following command: $

With the widespread application of the Linux operating system, more and more people are beginning to need to learn and understand the basic commands and shortcuts in the Linux system. In this article, we will introduce some commonly used Linux commands and shortcuts to help beginners understand the Linux system and improve work efficiency. Commonly used commands 1.1ls command The ls command is one of the most commonly used commands in Linux. It is mainly used to list files and subdirectories in the current directory. Commonly used options are: -l: Display file information in long format, including file type

In Python, parameters can be passed to scripts via the command line. These parameters can be used inside scripts to perform different actions based on different inputs. Detailed explanation of Python command line parameters: 1. Positional parameters: parameters passed to the script in order on the command line. They can be accessed through position inside the script; 2. Command line options: parameters starting with - or -, usually Used to specify specific options or flags for the script; 3. Pass parameter values: Pass parameter values through the command line.

Start the journey of Django project: start from the command line and create your first Django project. Django is a powerful and flexible web application framework. It is based on Python and provides many tools and functions needed to develop web applications. This article will lead you to create your first Django project starting from the command line. Before starting, make sure you have Python and Django installed. Step 1: Create the project directory First, open the command line window and create a new directory

Solution to the problem that javac is not an internal or external command and is not an operable program: 1. First download the latest version of JDK from the official website and install it; 2. Configure the system environment variables and add the jdk installation path to the path; 3. Enter the computer command Run the interface, enter "java -v" and the version number will appear.
