Learn How to Get IP Address of Website using Go Language. There are times when you want to read the IP address of the user and show it back to them. Same can be used to check your own IP. So the below video shows you how to do just that. You can check out how to look up through DNS and get IP address in go lang.
net.LookupHost() on your os.Hostname() are not going to be much of the use because they usually give the localhost address. So you may have to make use of the NET package or the other external libraries that can help you get the network address and then parse through the IP address.
These are the two packages that you are going to import in your code.
import (
"net"
"os"
)
Lot of people also make use of the LocalAddr().(*net.UDPAddr) to get the local machine IP when your system has more than one IP connected. This can be handy for those in the workplace. It helps to try some of the localaddr and UDP data for processing.
That being said the above video shows you how to get the IP address much more effective way. And you can pretty much get the accurate IP address. Hopefully the below video is useful for you to get the IP of the machine.
Tip for Go language Code Editor
Do note that the file for the golang has the .go file. Write the code, save the file and then run the code. Make sure to save the file before you run code.
Help me make more of such tutorials by checking out the sponsors. It won't cost you unless you wish to purchase and I only earn commission if you do. So If you want to host your blog and website Check out the WPEngine.
I hope you like the tutorial. Thanks for keeping tab on my content. I appreciate you taking time to read the post. Do let me know in the comments if you have any questions or comments.