|
最近接到一个需求,对一个域名的机器集群做一个分布式负载测试(写了一个简单的小程序,说明LR中域名如何反向获取IP地址),首先要获取一下域名的IP队列,下面用角本做了一个通过DNS获取www.sohu.com的IP地址的方法,获取后,再用平均分布对各IP集群做同等到压力负载,看各IP集群响应能力:
首先先要知道所在网络使用的DNS服务器:
在cmd模式下ipconfig一下,我这里的DNS是10.0.1.228
在LR角本中选用DNS角本,再进行下面的改写,我这里只是获取IP后打印出来,你可以获取后,保存队例,以便后面角本的使用
#include "mic_socket.h"
// -------------------------------------------------------------------------------
// DNS - Domain Name Service Vuser
// This virtual user scrīpt is designed to test hostname resolution against
// DNS servers. If a host address resolves to multiple addresses, all
// addresses are displayed in the output.
//
// Usage Notes:
// {DnsServer} - IP Address of a Domain Name Server
// {Hostname} - Name of host to resolve IP address for
//
// -------------------------------------------------------------------------------
Action()
{
char *results = NULL;
int rescnt = 0;
// Set DNS server IP Address,注意DNS要用本机的DNS的IP,错了则无法运行
lr_save_string("10.0.1.228","DnsServer");
// Set hostname to resolve
lr_save_string("www.sohu.com", "Hostname");
// Perform DNS Query
results = (char *) ms_dns_query("DnsQuery",
"URL=dns://{DnsServer}",
"QueryHost={Hostname}",
LAST);
// List all the results... (if more than one)
while (*results) {
rescnt++;
lr_log_message(
lr_eval_string("(%d) IP address for {Hostname} is %s"),
rescnt,
results);
results = (char *) ms_dns_nextresult(results);
}
return 0;
}
运行结果,你可以看到www.sohu.com所有的IP指向
Action.c(23): Notify: Transaction "DnsQuery" ended with "Pass" status (Duration: 0.0707).
(1) IP address for www.sohu.com is 61.152.234.73
(2) IP address for www.sohu.com is 61.152.234.75
(3) IP address for www.sohu.com is 61.152.234.76
(4) IP address for www.sohu.com is 61.152.234.77
(5) IP address for www.sohu.com is 61.152.234.71
(6) IP address for www.sohu.com is 61.152.234.72
知道了这些IP后,后面就不用我多说了,大家可以保存在数组中,随机的方式来对各IP施压,或灵活改变你模拟的压力比例,还可以在不同区域起同样的压力,知道某个IP的机器在网络上的访问情况 |
|