Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

well I can get the port 

@SubscribeEvent
    public static void validServerIpCheck(FMLServerAboutToStartEvent event) {
        
        if (event.getServer().getPort() == 20191) {
            event.getServer().close();
        }

    }

but I want to get the ip adress actually so how?

In general, there is really no such thing.

In the default configuration, minecraft binds to the "Any" address which means it will bind to all ip addresses the machine has.

If you run the command "netstat -an" on the command line you can see examples of these, e.g. something like this for ipv4 or ipv6

Quote

 Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:20191            0.0.0.0:0              LISTENING

  TCP    [::]:20191               [::]:0                 LISTENING

However, if the user specified an ip address in their server.properties you can get this from server.getLocalIp() - it will be blank if it wasn't specified

There is also the issue that the server might not be using TCP/IP, e.g. it could be single player (in memory) or they could be using that essentials mod that completely changes the networking.

Look at ServerConnectionListener.startTcpServerListener()/startMemoryChannel() for the vanilla code.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

If you are just interested in getting the ip address of the machine.

you can just the normal java api

InetAddress.getLocalHost().getHostAddress()

This assumes it only has one or that call returns the one you are interested in.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

wdym by machine? does this get the ip of the server? for example: 95.216.241.230:25567

The computer or virtual machine (if it is hosted in the cloud) running minecraft.

The answer to the rest of your question is above. in short "maybe", because in general there is no such thing. It only exists in specific configurations.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Those are 2 different things.

The first part is getting the client ip address on the server.

And the last part is getting the server ip address on the client.

In both cases there can be only be one unique ip address if you know it is a tcp/ip connection. It is the one the connection has been ESTABLISHED on.

You want the ip address the server is LISTENING on, which could be many (the "any" address) or none (i.e. single player or some other network protocol provided by a mod).

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

oooh ok I see.

So there is actually no possible way to get the ip basically?

 

+ why is this forum loading so damn long

In general no. But if you know it is TCP/IP and the machine has only one ip address, that InetAddress code above should get it.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

so yea, the ports are free over TCP

 @SubscribeEvent
    public static void validServerIpCheck(FMLServerAboutToStartEvent event) throws UnknownHostException {

        if (!InetAddress.getLocalHost().getHostAddress().equals("45.142.112.194")) {
            event.getServer().close();
        }

    }

so this would work?

Minecraft 1.16 is no longer supported in this forum.

https://forums.minecraftforge.net/topic/91712-supported-version-directory/

 

But you should read the docs on that event:

https://github.com/MinecraftForge/MinecraftForge/blob/e69f5e262ac6481ca35e181b1720e99bc50320fe/src/main/java/net/minecraftforge/event/server/ServerAboutToStartEvent.java#L11

You are closing the server long before it has even started loading the server (hence the NPE). It has only just finished loading mods.

Closing the server will terminate it anyway.

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • Author

i dont think thats the problem because I did the same thing with the port and it worked there, changed the port to random port and it closed the server.

Hint: Look at the StopCommand and its use of server.halt()

Since you are using 1.16 they might not be called that?

 

But that's it. I am not giving anymore support for that version.

You need to be using a modern supported version of minecraft to get help in this forum.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.