Jump to content

how to get servers ip from forge server


jaxox

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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