1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83:
| uses NB30, WinSock, IdHTTP;
[...]
function GetMACAddress(): string; function GetAdapterInfo(Lana: Char): string; var AdapterStatus: TAdapterStatus; NCB: TNCB; begin FillChar(NCB, SizeOf(NCB), 0); NCB.NCB_COMMAND := Char(NCBRESET); NCB.NCB_LANA_NUM := Lana; if NetBios(@NCB) <> Char(NRC_GOODRET) then begin Result := '- MAC not found -'; Exit; end;
FillChar(NCB, SizeOf(NCB), 0); NCB.NCB_COMMAND := Char(NCBASTAT); NCB.NCB_LANA_NUM := Lana; NCB.ncb_callname := '*';
FillChar(AdapterStatus, SizeOf(AdapterStatus), 0); NCB.ncb_buffer := @AdapterStatus; NCB.ncb_length := SizeOf(AdapterStatus); if NetBios(@NCB) <> Char(NRC_GOODRET) then begin Result := '- MAC not found -'; Exit; end;
Result := IntToHex(Byte(AdapterStatus.Adapter_Address[0]), 2) + '-' + IntToHex(Byte(AdapterStatus.Adapter_Address[1]), 2) + '-' + IntToHex(Byte(AdapterStatus.Adapter_Address[2]), 2) + '-' + IntToHex(Byte(AdapterStatus.Adapter_Address[3]), 2) + '-' + IntToHex(Byte(AdapterStatus.Adapter_Address[4]), 2) + '-' + IntToHex(Byte(AdapterStatus.Adapter_Address[5]), 2); end;
var AdapterList: TLanaEnum; NCB: TNCB; begin Result := '';
FillChar(NCB, SizeOf(NCB), 0); NCB.ncb_command := Char(NCBENUM); NCB.ncb_buffer := @AdapterList; NCB.ncb_length := SizeOf(AdapterList); Netbios(@NCB); if Byte(AdapterList.length) > 0 then Result := GetAdapterInfo(AdapterList.lana[0]) else Result := '- MAC not found -'; end;
function GetInternetIP(): string; var Temp: string; begin Result := ''; Temp := IdHTTP1.Get('http://checkip.dyndns.org'); Result := Copy(Temp, Pos(':', Temp) + 2, Pos('</bo', Temp) - Pos(':', Temp) - 2); end;
function GetNetworkIP(): string; var WSA: TWSAData; Len: Integer; PHost: PChar; HostEnt: PHostEnt; begin Result := '';
WSAStartup($0101, WSA); Len := $FF; PHost := StrAlloc(Len); GetHostName(PHost, Len); HostEnt := GetHostByName(PHost);
with HostEnt^ do Result := Format('%d.%d.%d.%d', [Ord(H_Addr^[0]), Ord(H_Addr^[1]), Ord(H_Addr^[2]), Ord(H_Addr^[3])]);
StrDispose(PHost); WSACleanup; end; |