Checking if the message is an IP

Discussion in 'Plugin Development' started by NickDEV, Sep 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    NickDEV

    How can I check if the message sent is an IP? As we all know the IP structure is like this:

    x.x.x.x

    I would need to check if the message equals to:

    randomnumber.randomnumber.randomnumber.randomnumber

    How can I do that?
     
  2. Offline

    Hex_27

    Not just that. There's also the kinds like thisisaserver.no-ip.org

    As for what you're trying,
    1. Get the player's message
    2. Lets say your player's message is represented by x

    Code:
    String[] split = x.split(" ");
    for(String s: split){
    
    if(s.split(".").length() == 4) //then your x.x.x.x is found
    
    }
    But I have to warn you, if you're making an anti-advertising plugin, players find many ways to weasel out of this check
     
  3. Code:
    public final class IPUtils {
    
    private static final Pattern IPV4_PATTERN = Pattern.compile("\\A(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}\\z");
    private static final Pattern IPV6_STD_PATTERN = Pattern.compile("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,6}$");
    
    private IPUtils() {
    
    }
    
    public static boolean isIPv4Address(String IP) {
       return IPV4_PATTERN.matcher(IP).matches();
    }
    
    public static boolean isDomain(String IP) {
       return IPV6_STD_PATTERN.matcher(IP).matches();
    }
    }
    
     
  4. Offline

    linuxsudo

    Blocking periods won't be a efficient way to prevent advertisement, and it would cause alot of confusion and annoyance.
     
    ferrybig, XxgustaveseXx and Hex_27 like this.
  5. Offline

    Hex_27

  6. Offline

    XxgustaveseXx

    I think that too, but what more better for no other server in chat???
     
  7. Offline

    Boomer

    well, there IS that code block posted by MaTaMor that will detect an IP based on is REGEX pattern (an ip is not a random number.random number.random number.random number - the numbers range from 0 to 255, so someone can type 645.423.14.11 and it will come through just fine since its not an ip but some other jibberish...

    Find that pattern inside the chat, cancel it.
     
  8. Offline

    Pocketkid2

    Regular Expressions are your friend. There are plenty of great tutorials and basic reference guides for making good regular expressions.
     
  9. Blocking IPs on a server does not work. Period. There are so many ways of getting around it, it is truly impossible to block advertisement without staff moderation. Instead I recommend that you use a recording system. Check for •, periods, (dot), [dot], etc. When a player advertises, do not block them from it. Instead save the typed message to a file, showing exactly what is said. Inform them of the rule beforehand, and have a chat clearer plugin. Send a message to top trusted staff in-game whenever someone has newly advertised (make sure to tell them to keep it a secret).

    Result: They won't even suspect that the plugin is used. When they get banned they will assume someone snitched. Nobody will try and put the IP on signs because IPs are not blocked, so you won't have the issue of advertisement being impossible to find. What you should keep is anti-spam.
     
  10. Offline

    Pocketkid2

    You are technically right, no advertising blocking plugin is perfect, but a learning plugin can get close. Admins can add custom regexes to the plugin's checker manually when they see something or when the plugin automatically suggests it. I could see that being possible. Signs can also be checked for advertising as well.
     
Thread Status:
Not open for further replies.

Share This Page