根据群id查询服务器信息

根据群id查询对应所在前后端服务器的脚本思路

<?php
$db_arr = array(‘us’, ‘br’, ‘ru’);
foreach ($db_arr as $row) {
$conn = get_db_conn($row, $conn);
// 使用sid尝试查找
$sid = get_long_sid($sid, $conn);
$serverid = get_serverid_by_sid($sid, $conn);
mysql_close($conn);
if ($serverid) {
echo $serverid;
break;
}
}
/**
* 连接数据库
* @param string $db_host [description]
* @return [type] [description]
*/
function get_db_conn($db_host = ”, $db_name = ”) {
// 连接数据库
$db_user = ”;
$db_pass = ”;
$conn = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name, $conn);
// 返回数据库句柄
return $conn;
}
/**
* 获取长sid
* @param [type] $sid [description]
* @return boolean [description]
*/
function get_long_sid($sid, $conn) {
// 判断是否长sid
$sql = “select”;
$result = mysql_query($sql, $conn);
$ret = mysql_fetch_assoc($result);
if ($ret) return $sid;
else return FALSE;
}
/**
* [get_serverid_by_sid description]
* @param [type] $sid [description]
* @return [type] [description]
*/
function get_serverid_by_sid($sid, $conn) {
// 查询
$ret = mysql_query($sql);
return $ret;
}
上面是思路,下面是成品:

<?php
error_reporting(0);
echo “Please enter session id :\n”;
while(1){
$stdin = fopen(‘php://stdin’,’r’);
$num = trim(fgets($stdin,100));
fclose($stdin);
$id = $num;
if(!is_numeric($num)){
echo “Enter sid is not NO. Enter again please !\n”;
continue;
}
else
break;
}
function get_db_conn($db_host = ”, $db_name = ”,$db_user = ”,$db_pass = ”) {
$conn = mysql_connect($db_host, $db_user, $db_pass);
if(!$conn){
die(mysql_error());
}
return $conn;
}
get_db_conn(‘xxxxxx’,’xxxx’,’xxxx’,’xxxx’);
$result = mysql_query(“select sid from xxxxx where asid=$id”);
$serverid = mysql_fetch_assoc($result);
$sid = $serverid[sid];
if(!$sid){
$sid = $id;
}
mysql_close($conn);
get_db_conn(‘xxxx’,’xxxx’,’xxxx’,’xxx’);
$result1 = mysql_query(“select server_id from sess_status.sessions where session_id=$sid”);
$serverid1 = mysql_fetch_assoc($result1);
$server_id = $serverid1[server_id];
if(!$server_id){
echo “This sid is not in DDOS-STATUS!”;
}
else
{
$session_ip = mysql_fetch_assoc(mysql_query(“select * from sess_status.servers where server_id=$server_id”));
echo “session_ip \n”;
echo ” | \n”;
echo ” V \n”;
echo “$session_ip[ip]\n”;
echo “\n”;
echo “================\n”;
echo “\n”;
$req = mysql_query(“select ip from sess_status.servers where server_id in (select node_server_id from sess_status.server_cluster where master_id=$server_id and node_server_type=2)”);
//$session_frond_ip = mysql_fetch_array($req);
echo “session_frond_ip \n”;
echo ” | \n”;
echo ” V \n”;
while($row = mysql_fetch_array($req)){
echo $row[‘ip’].”\n”;
}
}
?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>