其实很简单,通过公开的查询接口获取JSON,解析即可。
IPV4:
CX_URL := 'http://whois.pconline.com.cn/ipJson.jsp?json=true&ip=';
try
JSONStr := form1.IdHTTP1.Get(CX_URL + ipv4);
if JSONStr <> '' then
begin
aJson:=TJSONObject.ParseJSONValue(Trim(JSONStr)) as TJSONObject;
if aJson.GetValue('ip').ToString<> '' then
begin
pro:=aJson.GetValue('pro').ToString.Replace(#34,'');
city:=aJson.GetValue('city').ToString.Replace(#34,'');
region:=aJson.GetValue('region').ToString.Replace(#34,'');
addr:=aJson.GetValue('addr').ToString.Replace(#34,'');
end;
IPv6: