...
Below code get local IP address assigned, and update DNS at http://dnszi.com
| Code Block | ||
|---|---|---|
| ||
function UpdateDNSByLocalIP(dnszi_user_id, dnszi_auth_key, dnszi_domain, dnszi_record: string):string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: array [0..63] of Ansichar;
i: Integer;
GInitData: TWSADATA;
IdHTTP: TIdHTTP;
MyIP, url, S: string;
begin
WSAStartup($101, GInitData);
MyIP := '';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(Buffer);
if phe = nil then
Exit;
pptr := PaPInAddr(phe^.h_addr_list);
i := 0;
while pptr^[i] <> nil do
begin
MyIP := StrPas(inet_ntoa(pptr^[i]^));
Inc(i);
end;
WSACleanup;
// update DNS
IdHTTP := TIdHTTP.Create(nil);
try
url := 'http://ddns.dnszi.com/set.html?user=' + dnszi_user_id + '&auth=' + dnszi_auth_key + '&domain=' + dnszi_domain + '&record=' + dnszi_record + '&ip=' + MyIP;
S := IdHTTP.Get( url);
finally
IdHTTP.Free;
end;
Result := S;
end; |
...
Below code just update domain name by public IP address combined with your router instead of local IP address actually assigned to your computer.
| Code Block | ||
|---|---|---|
| ||
function UpdateDNSByLocalIP(dnszi_user_id, dnszi_auth_key, dnszi_domain, dnszi_record: string):string;
var
IdHTTP: TIdHTTP;
url, S: string;
begin
// update DNS
IdHTTP := TIdHTTP.Create(nil);
try
url := 'http://ddns.dnszi.com/set.html?user=' + dnszi_user_id + '&auth=' + dnszi_auth_key + '&domain=' + dnszi_domain + '&record=' + dnszi_record;
S := IdHTTP.Get( url);
finally
IdHTTP.Free;
end;
Result := S;
end; |
...