Jump to content

Checking if an account is banned


Explv

Recommended Posts

Java:

 

Depends on Apache's HTTPClient

 

Would be interested to know if someone has a better way of doing this

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class BanChecker {

    public final boolean isBanned(final String username, final String password) throws IOException {
        HttpClient httpClient = HttpClientBuilder.create().build();

        // Login to the account
        HttpResponse loginResponse = login(httpClient, username, password);

        // Go to the account settings page
        HttpResponse accountSettingsResponse = getAccountSettings(httpClient, loginResponse);

        // Get the account history link from the account settings page
        Optional<String> accountHistoryLink = getAccountHistoryLink(accountSettingsResponse.getEntity().getContent());

        if (!accountHistoryLink.isPresent()) {
            System.out.println("Could not find account history link on settings page");
            return false;
        }

        // Go to the account history page
        HttpGet accountHistoryRequest = new HttpGet(accountHistoryLink.get());
        HttpResponse accountHistoryResponse = httpClient.execute(accountHistoryRequest);

        // Search the account history page to check if account is banned
        return isAccountStatusBanned(accountHistoryResponse.getEntity().getContent());
    }

    private HttpResponse login(final HttpClient httpClient, final String username, final String password) throws IOException {
        HttpPost loginRequest = new HttpPost("https://secure.runescape.com/m=weblogin/login.ws");

        loginRequest.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        loginRequest.addHeader("Accept-Encoding", "gzip, deflate, br");
        loginRequest.addHeader("Accept-Language", "en-GB,en-US;q=0.8,en;q=0.6");
        loginRequest.addHeader("Cache-Control", "max-age=0");
        loginRequest.addHeader("Connection", "keep-alive");
        loginRequest.addHeader("Content-Type", "application/x-www-form-urlencoded");
        loginRequest.addHeader("Host", "secure.runescape.com");
        loginRequest.addHeader("Origin", "https://secure.runescape.com");
        loginRequest.addHeader("Referer", "https://secure.runescape.com/m=weblogin/loginform.ws?mod=www&ssl=1&expired=0&dest=account_settings.ws");
        loginRequest.addHeader("Upgrade-Insecure-Requests", "1");
        loginRequest.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");

        List<NameValuePair> loginParameters = new ArrayList<>();
        loginParameters.add(new BasicNameValuePair("username", username));
        loginParameters.add(new BasicNameValuePair("password", password));
        loginParameters.add(new BasicNameValuePair("mod", "www"));
        loginParameters.add(new BasicNameValuePair("ssl", "1"));
        loginParameters.add(new BasicNameValuePair("dest", "account_settings.ws"));

        loginRequest.setEntity(new UrlEncodedFormEntity(loginParameters));

        return httpClient.execute(loginRequest);
    }

    private HttpResponse getAccountSettings(final HttpClient httpClient, final HttpResponse loginResponse) throws IOException {
        HttpGet accountSettingsGetRequest = new HttpGet(loginResponse.getFirstHeader("Location").getValue());
        return httpClient.execute(accountSettingsGetRequest);
    }

    private Optional<String> getAccountHistoryLink(final InputStream accountSettings) throws IOException {
        Pattern accountHistoryLinkPattern = Pattern.compile("src=\"([^\"]+account_history.ws)\"");

        try (BufferedReader settingsReader = new BufferedReader(new InputStreamReader(accountSettings))) {
            String settingsLine;
            while ((settingsLine = settingsReader.readLine()) != null) {
                Matcher accountHistoryLinkMatcher = accountHistoryLinkPattern.matcher(settingsLine);
                if (accountHistoryLinkMatcher.find()) {
                    return Optional.of(accountHistoryLinkMatcher.group(1));
                }
            }
        }
        return Optional.empty();
    }

    private boolean isAccountStatusBanned(final InputStream accountHistoryPage) throws IOException {
        try (BufferedReader accountStatusReader = new BufferedReader(new InputStreamReader(accountHistoryPage))) {
            String accountStatusLine;
            while ((accountStatusLine = accountStatusReader.readLine()) != null) {
                if (accountStatusLine.contains("<b>Banned:</b>")) {
                    return true;
                }
            }
        }
        return false;
    }
}

 

Python 3:

 

import re
import requests

def is_banned(username, password):
    session = requests.Session()
    login_response = login(session, username, password)
    url_account_id = get_url_account_id(session, login_response)
    account_history = get_account_history(session, url_account_id)
    return'<b>Banned:</b>' in account_history.text

def login(session, username, password):
    login_url = 'https://secure.runescape.com/m=weblogin/login.ws'

    data = {
        'username': username,
        'password': password,
        'mod' : 'www',
        'ssl' : '1',
        'dest' : 'account_settings.ws'
    }

    headers = {
        "Accept" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
        "Accept-Encoding" : "gzip, deflate, br",
        "Accept-Language" : "en-GB,en-US;q=0.8,en;q=0.6",
        "Cache-Control" : "max-age=0",
        "Connection" : "keep-alive",
        "Content-Type" : "application/x-www-form-urlencoded",
        "Host" : "secure.runescape.com",
        "Origin" : "https://secure.runescape.com",
        "Referer" : "https://secure.runescape.com/m=weblogin/loginform.ws?mod=www&ssl=1&expired=0&dest=account_settings.ws",
        "Upgrade-Insecure-Requests" : "1",
        "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36"
    }

    return session.post(login_url, data=data, headers=headers, allow_redirects=False)

def get_url_account_id(session, login_response):
    login_redirects = session.resolve_redirects(login_response, login_response.request)

    # We are interested in the second redirect, so skip the first
    next(login_redirects)

    login_redirect = next(login_redirects)

    return re.search('c=[^/]+', login_redirect.url).group(0)
    
def get_account_history(session, url_account_id):
    return session.get('https://secure.runescape.com/m=offence-appeal/' + url_account_id + '/account_history.ws')
 

Edited by Explv
  • Like 10
Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 1 year 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...