{"id":197,"date":"2007-05-12T16:55:42","date_gmt":"2007-05-12T14:55:42","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/getting-the-local-ip-address\/"},"modified":"2007-05-12T16:55:44","modified_gmt":"2007-05-12T14:55:44","slug":"getting-the-local-ip-address","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/getting-the-local-ip-address\/","title":{"rendered":"Getting the Local IP Address"},"content":{"rendered":"<p><em>> How can you get the IP address for the local computer?<br \/>\n> Your help is appreciated&#8230;<br \/>\n<\/em><br \/>\nThe following function will give you the IP address. You will have to<br \/>\ninclude Winsock.pas<br \/>\n<!--more--><br \/>\n[code lang=&#8221;delphi&#8221;]function GetIPAddress : string;<br \/>\nvar<br \/>\n   Sdata : TWSAData;<br \/>\n   ErrorCode: Integer;<br \/>\n   HEnt: PHostEnt;<br \/>\n   IPAddr : TInAddr;<br \/>\n   CName : PChar;<br \/>\n   iSize : longword;<br \/>\nbegin<br \/>\n     isize := MAX_COMPUTERNAME_LENGTH;<\/p>\n<p>     GetMem(CName, iSize);<\/p>\n<p>     Try<br \/>\n        GetComputerName(CName, iSize);<\/p>\n<p>        ErrorCode := WSAStartup($0101, SData);<\/p>\n<p>        if ErrorCode = 0 then<br \/>\n        begin<br \/>\n          Try<br \/>\n             HEnt := GetHostbyName(CName);<\/p>\n<p>             if HEnt <> nil then<br \/>\n             begin<br \/>\n                  with IPAddr, HEnt^ do<br \/>\n                  begin<br \/>\n                    S_un_b.s_b1 := h_addr^[0];<br \/>\n                    S_un_b.s_b2 := h_addr^[1];<br \/>\n                    S_un_b.s_b3 := h_addr^[2];<br \/>\n                    S_un_b.s_b4 := h_addr^[3];<br \/>\n                  end;<br \/>\n                  Result := inet_ntoa(IPAddr);<br \/>\n             end;<br \/>\n          Finally<br \/>\n                 ErrorCode := WSACleanup;<br \/>\n          end;<br \/>\n        end;<br \/>\n     Finally<br \/>\n            FreeMem(CName);<br \/>\n     end;<br \/>\nend;<br \/>\n[\/code]<br \/>\nregards<br \/>\nStephan Marais<\/p>\n<p>[tags]Delphi, Network[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>> How can you get the IP address for the local computer? > Your help is appreciated&#8230; The following function will give you&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[75,116],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-3b","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/197"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=197"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/197\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}