Hi Leute,
wie kann man die locale Netzwerkadresse des Rechners ermitteln. Das Programm laeuft auf dem Rechner und ich will halt wissen welche IP Adresse er hat.
Danke schonmal im voraus.
Gruß,
Torakas
Locale IP Adresse ermitteln
- Hroudtwolf
- Beiträge: 1416
- Registriert: 30.10.2004 23:33
- Kontaktdaten:
Quelle:PureBoardArchiv
NEO im Archiv hat geschrieben: Wenn du die Tcp/Ip Adresse deines Rechners meinst, dann geht das:
Code: Alles auswählen
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.w
h_length.w
h_addr_list.l
EndStructure
If InitNetwork()
Hostname$ = Space(255)
gethostname_(Hostname$,255)
Debug "Hostname: "+Hostname$
pHostinfo = gethostbyname_(Hostname$)
If pHostinfo = 0
Debug "Unable to resolve domain name."
Else
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype <> #AF_INET
Debug "A non-IP address was returned."
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
Debug StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0)
AdressNumber+1
Wend
EndIf
EndIf
Else
Debug "Network can't be initialized"
EndIf
PWS32 im Archiv hat geschrieben: Da...
Code: Alles auswählen
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.w
h_length.w
h_addr_list.l
EndStructure
Structure SERVER_INFO_101
dwPlatformId.l
lpszServerName.l
dwVersionMajor.l
dwVersionMinor.l
dwType.l
lpszComment.l
EndStructure
#MAX_PREFERRED_LENGTH = -1
#SV_TYPE_ALL = $FFFFFFFF
#NERR_SUCCESS = 0
#ERROR_MORE_DATA = 234
#MainWindow = 100
#MMTB = 200
Global MMTextBox
Procedure Message (M.s)
WriteMessage.s
WriteMessage +Chr(13)+Chr(10)+M
SetGadgetText(#MMTB,GetGadgetText(#MMTB) + WriteMessage )
SendMessage_(MMTextBox,$00B6,0,10000)
EndProcedure
Procedure.s GetIPbyName (NameIP.s)
TheIPAdress.s
If InitNetwork()
pHostinfo = gethostbyname_(NameIP)
If pHostinfo = 0
TheIPAdress = "Unable to resolve domain name"
Else
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype <> #AF_INET
MessageRequester("Info","A non-IP address was returned",0)
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
TheIPAdress = StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0)
AdressNumber+1
Wend
EndIf
EndIf
Else
MessageRequester("Info","Network can't be initialized",0)
EndIf
ProcedureReturn TheIPAdress
EndProcedure
Procedure GetLANList()
IPResult.s
se101.SERVER_INFO_101
nStructSize = SizeOf(SERVER_INFO_101)
RetCode = NetServerEnum_(0, 101, @bufptr, #MAX_PREFERRED_LENGTH, @dwEntriesread, @dwTotalentries, #SV_TYPE_ALL, 0, @dwResumehandle)
If RetCode = #NERR_SUCCESS And RetCode <> #ERROR_MORE_DATA
For i = 0 To dwEntriesread - 1
CopyMemory( bufptr + (nStructSize * i),@se101, nStructSize)
Buffer.s=Space(512)
Result=WideCharToMultiByte_(#CP_ACP ,0,se101\lpszServerName,255,@Buffer.s,512,0,0)
IPResult = GetIPbyName (Buffer)
Message ("No : "+ Str(i+1) + " " + Buffer + " --> " + IPResult)
Next
Else
MessageRequester("Info","Failed",0)
EndIf
NetApiBufferFree_(bufptr)
SendMessage_(MMTextBox,$00B6,0,30)
EndProcedure
hWnd = OpenWindow(#MainWindow, 100, 150, 300, 250, #PB_Window_SystemMenu , " Name > IP")
If CreateGadgetList(WindowID())
ButtonGadget(1, 1, 224, WindowWidth()-1,26, "Get Name and IP")
MMTextBox=StringGadget(#MMTB, 0, 2, WindowWidth()-1,WindowHeight()-30 ,"Name > IP by P.Spisla 2003 ",#PB_String_Multiline|#ES_AUTOVSCROLL|#WS_VSCROLL|#PB_String_ReadOnly)
Message("--------------------------------------------")
EndIf
;GetLANList()
Repeat
Select WaitWindowEvent()
Case #PB_EventGadget
Select EventGadgetID()
Case 1
Message ("Examine the Network, please wait !")
GetLANList()
Message ("End of List")
EndSelect
Case #PB_EventCloseWindow
End
EndSelect
ForEver