Networks

Windows specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by lee__48.

Hiya. I'm experimenting with PB's network commands. It is a bit annoying having to find your IP address each time you want to connect to a "server". Is there anyway to, either display your computers IP address, or have the "client" program located the server by itself (without need for the ip address).

Any help gratefully received.

Lee.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hi lee_48,
welcome to pure comunity. just take a look to the tips/tricks section and to beginners section! If you dont find anything, use "search" function and seach on all posts of this forum! There are a lot of examples and posts to this topic :wink:


greetz
MrVainSCL! aka Thorsten

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

With IPX it should be possible to find the server in LANs or you do a "PortScan" on all network IPs and search for valid server-responses. Anyway, not a smart solution. I dont like Games which do not ask for a IP and searches his servers itselfe.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by lee__48.
Originally posted by tranquil

With IPX it should be possible to find the server in LANs or you do a "PortScan" on all network IPs and search for valid server-responses. Anyway, not a smart solution. I dont like Games which do not ask for a IP and searches his servers itselfe.
How could I get the computer's IP address to show up on the status bar. If I could get the IP address of the "server" without using "winipcfg.exe" that would be suitable for what I am doing.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by dmoc.

http://www.allapi.net
Download API-Guide, this and many other q's easily answered (well ok maybe not so easily :wink:
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Sebi.

Hi Lee_48,
here is the code to get the local IP-address!

Code: Select all

Procedure.l CpyMemory(Source.l,Dest.l,Length.l)
For I =1 To Length
PokeB(Dest+I-1,PeekB(Source+I-1))
Next I
ProcedureReturn Length
EndProcedure
Procedure.l PeekBLong(Addr.l)
Lng.l=0
PokeB(@Lng,PeekB(Addr))
ProcedureReturn Lng
EndProcedure
Procedure.s GetIPAddress()
Ret.l=0
Tel.l=0
ResultIP.s=""
NullPointer.l=0
GetIpAddrTable_(@NullPointer,@Ret,-1)
If Ret >0
IP_Mem.l=AllocateMemory(100,@Ret,0)
GetIpAddrTable_(IP_Mem,@Ret,0)
PokeL(@EntryCount.l,PeekL(IP_Mem))
For Tel=0 To EntryCount-1
dwAddr.l=IP_Mem+4+(Tel*(5*4+2*2))
dwMask.l=IP_Mem+4+(Tel*(5*4+2*2))+8
IP_Address.s=Str(PeekBLong(dwAddr))+"."+Str(PeekBLong(dwAddr+1))+"."+Str(PeekBLong(dwAddr+2))+"."+Str(PeekBLong(dwAddr+3))
IP_SubnetMask.s=Str(PeekBLong(dwMask))+"."+Str(PeekBLong(dwMask+1))+"."+Str(PeekBLong(dwMask+2))+"."+Str(PeekBLong(dwMask+3))
If Left(IP_SubnetMask,13)="255.255.255.0"
FreeMemory(100)
ProcedureReturn IP_Address
EndIf
Next
FreeMemory(100)
EndIf
ProcedureReturn ""
EndProcedure

MessageRequester("",GetIPAddress(),0)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Welcome to the PureBasic Forum Sebi.

I'm truly sorry, but it doesn't work here on Win2k-SP3.

Here 3 functional examples:

Code: Select all

;Fred's code example:   (if my notes are correct...)

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

Next example:

Code: Select all

; Danilo's code example:   (if my notes are correct...)

IPmax = 10
Dim localips$(IPmax)
 
 
    Procedure.l getIPs()
      Shared localIPs$,IPmax
      *buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 65536)
      Dim localIPs$(IPmax)  ; Remove all existent IPs from list ( REDIM = Clear )       
      a=gethostname_(*buffer,2048)
      localIPs$(0) = UCase(PeekS(*buffer))
      adr.l=gethostbyname_(*buffer)
      h_name.l=PeekL(adr.l) ;Point to host name
      ip=0:offset.l=0
        Repeat
          h_addr_list=PeekL(adr.l+16+offset.l) ; List of Addresses (IPs)
          ipadr.l=h_addr_list
             If h_addr_list0
               ;localIPs$(ip+1)=StrU(PeekB(ipadr.l),0)+"."+StrU(PeekB(ipadr.l+1),0)+"."+StrU(PeekB(ipadr.l+2),0)+"."+StrU(PeekB(ipadr.l+3),0)
               localIPs$(ip+1)=StrU(PeekB(ipadr.l),#Byte)+"."+StrU(PeekB(ipadr.l+1),#Byte)+"."+StrU(PeekB(ipadr.l+2),#Byte)+"."+StrU(PeekB(ipadr.l+3),#Byte)
               ;st$+localIPs$(ip)+Chr(10)
               ip+1:offset.l+4
             EndIf
        Until h_addr_list=0
      ProcedureReturn ip
    EndProcedure
 
 
If InitNetwork()
   IPcount = getIPs()
   If IPcount
     A$ = "IP´s available on: "+Chr(13)+Chr(13)+Chr(34)+localIPs$(0)+Chr(34)+Chr(13)+Chr(13)
     For a = 1 To IPcount
         A$ + "IP " + Str(a) + " :   " + localIPs$(a) + Chr(13)
     Next a
   Else
     A$ = "No IP´s found"
   EndIf
   MessageRequester("IP INFO",A$,0)
Else
   MessageRequester("ERROR","Cant initialize Network!",0)
EndIf

Next example:

Code: Select all

; Tranquil's & Mr.Vain's code example:

;---------------------------
; GET IP Example
;
;NetWork References...
;
;[url]http://www.vbip.com/winsock-api/gethostname/gethostname-01.asp[/url] -> How To get name And IP address of the local system
;[url]http://www.vbapi.com/ref/h/hostent.html[/url] -> HOSTENT Structure
;
;If you need all IPs of your system, its much as easy, please call us if you have problems.
;
;Tranquilizer & Mr.Vain of Secretly!
;---------------------------


a=initnetwork()
*buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 2048)

Procedure.l calc(va.b)
  If va.b
Post Reply