get ip address

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
bacardirigoman
New User
New User
Posts: 6
Joined: Sun Feb 20, 2005 10:35 pm

get ip address

Post by bacardirigoman »

I tried to write a simple platform independent server. It should run on linux as well on windows.
But there is one function really missing in the network library.
getclientip(client)
It should return the IP-address of the specific client. That would be great. Then I don't have to do my server in Java :-/
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

Hi,

On Windows, I know it is possible, there is an example in CodeArchiv. But on Linux, I don't know.
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Post by nco2k »

having that command natively in pb, would be indeed a nice thing. :wink:

c ya,
nco2k
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

i agree
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

the only way around is i guess go native winsock ie. berkely socket io
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

good for windows, not for linux
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

linux should have socket support as well! but don't ask me how to do it :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Of course linux has API sockets, but this is a Basic language. API involvement should be kept to a minimum.
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

I think that function is possible to add in Windows and Linux because for example, Apash on Windows and Linux can log IP addresses. And I think it would be good to add this function to PB... Fred, what do you think ? Is my remark stupid like ReceiveNetworkString() ? ;-)
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

Until it's added, or someone create a little userlib.
This one work with windows & linux:

Code: Select all

Procedure.s GetClientIP(ClientID)
  Structure IPType
   Reserved.w
   Port.w
   StructureUnion
    IPLong.l
    IP.b[4]
   EndStructureUnion
   Zeros.l[2]
  EndStructure
  
  s = SizeOf(IPType)
  
  res = getpeername_(ClientID, @IP.IPType, @s)
  If res = 0
   remotip$ = StrU(IP\IP[0], #Byte)+"."+StrU(IP\IP[1],#Byte)+"."+StrU(IP\IP[2], #Byte)+"."+StrU(IP\IP[3], #Byte)
  Else
   remotip$ = ""
  EndIf

  ProcedureReturn remotip$

EndProcedure
Use it like this:

Code: Select all

If InitNetwork()
  If CreateNetworkServer(8181) = 0 
    MessageRequester("Error", "Can't Create Server", 0)
    End
  EndIf

  Repeat

   event = NetworkServerEvent()
   
   If event = 1 ; Someone connected
    Debug GetClientIP(NetworkClientID()); Here you go
   EndIf
  ForEver
EndIf
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Ok, it will be added.
olejr
Enthusiast
Enthusiast
Posts: 152
Joined: Sun Jul 11, 2004 7:48 pm
Location: Lillehammer, No(r)way
Contact:

Post by olejr »

And then Fred came and saved the day.. :wink:

Just as I had the libs ready..
So if someone want's them until Fred adds it..

Windows->getclientip.zip
Linux->getclientip.tar.gz

Just copy into purelibraries(linux)/userlibraries(windows)
Works like the Procedure I posted earlier:

Code: Select all

ip$=GetClientIP(ClienID)
The source is there, but it ain't pretty..
Just a quick hack..

Oh.. And don't forget to remove the lib when Fred add the same command..
Last edited by olejr on Mon Mar 07, 2005 7:39 pm, edited 1 time in total.
Gansta93
Enthusiast
Enthusiast
Posts: 238
Joined: Wed Oct 20, 2004 7:16 pm
Location: The Village
Contact:

Post by Gansta93 »

Fred wrote:Ok, it will be added.
Thank you Fred ! :-D
Be seeing you! :-)

Gansta93
If you speak french, you can visite Le Monde de Gansta93 (Gansta93's World)
oliv
User
User
Posts: 42
Joined: Sun Aug 24, 2003 10:11 am
Location: France

Post by oliv »

Good Idea :D
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

At the same time can you add client event #4???

-Anthony
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply