Jump to content

IP Display Changer


Purple

Recommended Posts

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
Link to comment
Share on other sites

  On 1/22/2016 at 9:07 AM, Zappster said:

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);
  Quote
since you only need to set the IP once

 

facep.gif

 

Edited by Rudie
  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...
  On 1/22/2016 at 9:07 AM, Zappster said:

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

 

 

  On 1/22/2016 at 9:50 AM, Rudie said:

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.

Link to comment
Share on other sites

  • 6 months later...

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

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