Function GetMyIpAddress:String ; //获取本机IP地址
Var
Ip:String;
Ipstr:String;
ch:ARRAY[1..32] of CHAR ;
i:integer;
WSData:TWsAData;
MyHostHostEnt;
Begin
If WSAstartup(2,wsdata)<>0 Then Begin
Result := '';
Exit ;
End;
Try
If GetHostName(@ch[1],32)<>0 Then Begin
Result := '';
Exit ;
End;
Except
Result:= '' ;
Exit ;
End;
MyHost:=GetHostByName(@ch[1]);
If MyHost=Nil Then Begin
Result := '' ; //IP地址为空
Exit ;
End Else Begin
For i:=1 to 4 Do Begin
Ip:=Inttostr(Ord(MyHost.h_addr^[i-1]));
ipStr:=Ipstr+Ip;
If i<4 Then IpStr:=IpStr+'.' ;
End;
Result:=Ipstr ;
End;
End;