Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server ban IP on json request

My server ban IP for 10 minutes when i try to get data from it by app. I have 2 devices with 2 different IP. I try to load script in browser: devices load it correctly. Then i try to request data from app, after that in browser i get "host unavailable", but second device still load script in browser correctly, until i try to load data directly from app. I think the problem is in a some security setting which made automatically after server get specific amount of requests. Here is the log from cPanel:

cpanel log

Maybe in apache settings exist something like this:

if (browser == unknown || OS == unknown)
banIP(360000);

code of request:

.......
JSONObject json = null;
List<NameValuePair> pn = new ArrayList<NameValuePair>();
pn.add(new BasicNameValuePair("pn", getApplication()
    .getPackageName()));
try {
    json = jParser.makeHttpRequest(
"http://nastynoises.shunamicode.com/getlastappversion/get_latest_app_version_v2.php","GET", pn);
    } catch (Exception e) {
        }
.......

Making request look like:

http://nastynoises.shunamicode.com/getlastappversion/get_latest_app_version_v2.php?pn=com.shunamicode.nn

JsonParser:

makeHttpRequest(){
....
    DefaultHttpClient httpClient = new DefaultHttpClient();
    String paramString = URLEncodedUtils.format(params, "utf-8");
        url += "?" + paramString;
    HttpGet httpGet = new HttpGet(url);
    HttpResponse httpResponse = httpClient.execute(httpGet);
    HttpEntity httpEntity = httpResponse.getEntity();
    is = httpEntity.getContent();
....
}

Server return:

05-01 00:07:21.545: D/shunami(1087): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
05-01 00:07:21.545: D/shunami(1087): <html><head>
05-01 00:07:21.545: D/shunami(1087): <title>406 Not Acceptable</title>
05-01 00:07:21.545: D/shunami(1087): </head><body>
05-01 00:07:21.545: D/shunami(1087): <h1>Not Acceptable</h1>
05-01 00:07:21.545: D/shunami(1087): <p>An appropriate representation of the requested resource /getlastappversion/get_latest_app_version_v2.php could not be found on this server.</p>
05-01 00:07:21.545: D/shunami(1087): <p>Additionally, a 404 Not Found
05-01 00:07:21.545: D/shunami(1087): error was encountered while trying to use an ErrorDocument to handle the request.</p>
05-01 00:07:21.545: D/shunami(1087): </body></html>

php:

<?php
$response = array();
require_once __DIR__ . '/con.php';
$db = new DB_CONNECT();
if (isset($_GET["pn"])) {
    $result = mysql_query("SELECT * FROM `latest_versions` WHERE `package_name` = '".$_GET["pn"]."'");
    if (!empty($result)) {
        if (mysql_num_rows($result) > 0) {
            while ($row = mysql_fetch_array($result)) {
                $response["success"] = 1;
                $response["version"] = $row['version'];
                $response["approxdate"] = $row['approxdate'];
                echo json_encode($response);
            }
        } else {
            $response["success"] = 0;
            $response["message"] = "Package not exist";
            echo json_encode($response);
        }
    } else {
        $response["success"] = 0;
        $response["message"] = "Empty result";
        echo json_encode($response);
    }
} else {
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
    echo json_encode($response);
}
?>

I tried to delete all scripts and request again but a server still ban. I don't have many practice and this error put me in deadlock.

like image 909
shunamicode Avatar asked Jun 06 '26 05:06

shunamicode


1 Answers

I found a solution. Now my app work fine, like before. But it can't be the answer on question, it's a bypass: server return response when i set BasicHttpParams(), so JSONParser now work:

....
int TIMEOUT_MILLISEC = 10000; 
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams,
                    TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient httpClient = new DefaultHttpClient(httpParams);
....

Question is still open

like image 109
shunamicode Avatar answered Jun 08 '26 17:06

shunamicode