문제

I need an ip address of a local host in order to use it in an url string. I want to connect to other computer by using port forwarding. The connecting will be written in a bash script.

So, is there a way to generically parse an ip address of a localhost?

도움이 되었습니까?

해결책

Translated into an IP address, commonly a localhost is always designated as 127.0.0.1. So generally, you can consider the loop back address same for every machine.

To get address other than 127.0.0.1 you may use the following bash command: hostname -i.

다른 팁

One of many solutions:

localhost_ip_address=`ping -c 1 localhost | head -n 1 | cut -d'(' -f2 | cut -d')' -f1`
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top