How to get global IP address? (SOLVED)

Hello guys!

I’m trying to make online game. Then I want to get “global IP address”.
How can I get global IP address with Lua?

sys.get_if_addrs() will return a list of all available network interfaces. You can iterate that list to find a network interface that is up and public:

Thank you for your reply!
I know that way. But I think it returns only local address.
image

But I want to get global(public) IP address. (like 126.***.***.***)
image
https://www.myglobalip.com/

Please give me more information

If you’re behind a router (which I guess most people are) then you won’t be able to tell your public IP from a call to sys.get_ifaddrs(). As you can see from this StackOverflow post there’s no dead simple way of knowing your public IP without making a connection somewhere and checking the result:

What do you plan to do with the public IP once you have it?

1 Like

I want to copy it on clipboard and make it easy to connect server.
Some people think it is difficult to find global IP.

Ok, got it. Easy solution:

  1. Make http.request() to https://api.ipify.org?format=json
  2. Parse returned json
  3. Show public IP

Read more here: https://www.ipify.org/

There’s also https://seeip.org/ and probably several others as well.

3 Likes

Thank you for your support!!
I could get global address :smiley:

1 Like

Your router/modem gets a dynamic IP from ISP whenever you connect it to Internet. This address as name says is changing. If you want a constant public IP from ISP, you must request ISP for the same. This comes at a very high cost and not recommended unless you are serving a high revenue generating data on that machine.

1 Like