Jump to content

IP Display Changer


Recommended Posts

Posted

Changes your OSBot frame title to show your current IP address of your bot.

 

Source

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

@ScriptManifest(author = "Purple", name = "IP Display Changer", version = 1.01, info = "Changes the title of your osbot to display your bots IP address.", logo = "")
public class Display extends Script {

    @Override
    public int onLoop() throws InterruptedException {
        changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
        stop(false);
        return 0;
    }

    public void changeFrameTitle(final String title) {
        for(Frame frame : Frame.getFrames()) {
            if(frame.isVisible() && frame.getTitle().startsWith("OSBot")) {
                SwingUtilities.invokeLater(() -> frame.setTitle(title));
                break;
            }
        }
    }

    public String getCurrentIPAddress() {
        try {
            URL url = new URL("http://myip.dnsomatic.com/");
            BufferedReader b = new BufferedReader(new InputStreamReader(url.openStream()));
            String ip = b.readLine();
            b.close();
            return ip;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "null";
    }
}
 

Aaes83X.png

  • Like 9
Posted (edited)

Wouldn't this be less intensive if this was in the onStart() instead on onLoop() since you only need to set the IP once? Nice job anyways

emote32342.png

 @Override
    public int onLoop() throws InterruptedException {
        changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
        stop(false);
        return 0;
    }
changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
stop(false);
stop(false);
since you only need to set the IP once

 

facep.gif

 

Edited by Rudie
  • Like 2
  • 4 weeks later...
Posted

Wouldn't this be less intensive if this was in the onStart() instead on onLoop() since you only need to set the IP once? Nice job anyways

 

 

emote32342.png

 @Override
    public int onLoop() throws InterruptedException {
        changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
        stop(false);
        return 0;
    }
changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
stop(false);
stop(false);

facep.gif

XD

 

onstart is still the proper use tho.

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...