'Storing Ipv4 address into a .env variable
I am trying to find a way on how to store a IPV4 address into a variable in .ENV file in my ReactJS project, but my problems are:
1.) How can I get the IPV4 address by using either a batch file or an environmental file?
2.) If I am using a Batch file, how can I write the IPV4 address, that I have gotten, into the .env file?
Why am I trying to do this?
I have been creating a MERN app, and this works only in a LAN network. To access this web application I need to use my device's IP address as the hostname of the URL, but the problem is, whenever I connect to my Wifi my IPv4 changes, and I think it is too hassle to change it over and over again as my IPv4 changes.
If you guys have any idea please feel free to share it with me :) Thank you so much in advance!
Solution 1:[1]
Here are a couple of examples of ways you could do this:
for /f "tokens=3" %%g in ('%__APPDIR__%netsh.exe interface ipv4 show config "Wi-Fi" ^|findstr "IP Address"') do set "_IPAddress=%%g"
Replace "Wi-Fi" with the name of your interface.
for /f "tokens=2 delims={;" %%g in ('%__APPDIR__%wbem\WMIC.exe nicconfig where "IPEnabled='TRUE'" get IPAddress /format:csv') do set "_IPAddress=%%g"
This one requires wmic to be installed, which may not be the case with Windows 11.
Once you have set the IP Address to a variable, you can use it like echo %_IPAddress%.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
