PureBasic Forum
https://www.purebasic.fr/english/

Get IP
https://www.purebasic.fr/english/viewtopic.php?f=5&t=2902
Page 1 of 1

Author:  BackupUser [ Mon Oct 15, 2001 3:28 pm ]
Post subject: 

Restored from previous forum. Originally posted by tranquil.

Howdy ho!

At first a hello to all Pure Users. I'm a newbie and want to code my first application.
This should be a File-Sharing tool like Napster but optimized for LAN Partys.

And here are my short Problems:

1.)
I need to find out the Local IP(s)where the client/server is running.
Is there a source code available or a System-Command?

2.)
Bug or not!? Hm, If I use the "StatusBarText" Command in combination with the Network Library my Server Recieves Crap Messages from the clients. (Sometime it works, other times the server recieve the same text that I put in the Statusbar)

Thanks for any help!

Mike

Tranquilizer/ Secretly!

Author:  BackupUser [ Mon Oct 15, 2001 11:36 pm ]
Post subject: 

Restored from previous forum. Originally posted by Franco.

Willkommen Michael!
Tryed to help but I don't get the right result.(I'm not a prof coder)

The commands that you have to use are:

WSAStartup_() needs 2 parameters -> initializes the wsock stuff
GetHostName_() needs 2 parameters -> get the Hostname
GetHostByName_() 1 parameter -> get the HostIP# from the Hostname
WSACleanUp_() -> this has to be!

I get the right result from GetHostName_() but after that, you have to use
GetHostByName_() and the return of it is a pointer to a pointer to....
And I really don't get it, sorry.

But if you don't get lost in pointers (like me ) probably this could be a help,
now that you know where to start.



Have a nice day...
Franco

Author:  BackupUser [ Tue Oct 16, 2001 12:02 am ]
Post subject: 

Restored from previous forum. Originally posted by fred.

Quote:
The commands that you have to use are:

WSAStartup_() needs 2 parameters -> initializes the wsock stuff
WSACleanUp_() -> this has to be!



Don't call these commands anymore ! There are called in InitNetwork and when a program ends..


Fred - AlphaSND

Author:  BackupUser [ Tue Oct 16, 2001 10:36 am ]
Post subject: 

Restored from previous forum. Originally posted by tranquil.

Okay, I will check the "pointer 2 pointer" version today. :)
The Problem is that a maschine can have more then one IP at the same time, URGS,
but thanks a lot, possible u helped me a little bit.

Mike (and my name is not Michael! *smile*)


Tranquilizer/ Secretly!

Author:  BackupUser [ Thu Oct 18, 2001 11:51 pm ]
Post subject: 

Restored from previous forum. Originally posted by Ants.

Quote:

GetHostName_() needs 2 parameters -> get the Hostname
GetHostByName_() 1 parameter -> get the HostIP# from the Hostname


These commands, as far as I know, are for getting the the IP of your machine, or the ASCII name of a known IP address. To get the IP of another machine, you have to do it manually, ie: tell people what it is, or run a Domain Name Server on your LAN, then create an entry for your Server as an ASCII name - like `FileServer'.
Either that or use Windows filesharing functions- ie: to look up what machines are in your Network Neighbourhood.

Cyas- Ants

Anton Reinauer

Author:  BackupUser [ Fri Oct 19, 2001 12:43 pm ]
Post subject: 

Restored from previous forum. Originally posted by tranquil.

I need the IP of the local machine, not of another one.
But to get it it seems to be very hard.

does anyone have a source for this??

Tranquilizer/ Secretly!

Author:  BackupUser [ Sat Oct 20, 2001 2:26 pm ]
Post subject: 

Restored from previous forum. Originally posted by MrVainSCL.

Hi tranquil - my little silly cousin :wink: - here is the solution how to find your local ips!It was much as easier as coding a "hello world" in pb :wink:) Have fun...

;---------------------------
; GET IP Example
;
;NetWork References...
;
;http://www.vbip.com/winsock-api/gethostname/gethostname-01.asp -> How To get name And IP address of the local system
;http://www.vbapi.com/ref/h/hostent.html -> 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<=0
res.l=256+va.b
Else
res.l=va.b
EndIf
ProcedureReturn res.l
EndProcedure


a=gethostname_(*buffer,2048)

adr.l=gethostbyname_(*buffer)

h_name.l=peekl(adr.l) ;Point to host name
h_array.l=peekl(adr.l+4) ; Pointer to an Array -- NOT REQUIRED YET
h_addrtype=peekl(adr.l+8) ; Addr type Integer -- NOT REQUIRED YET
h_length=peekl(adr.l+12) ;Length as integer -- NOT REQUIRED YET
h_addr_list=peekl(adr.l+16) ; List of Addresses (IPs)

ipadr.l=h_addr_list

ipb1.b=peekb(ipadr.l)
ip1.l=calc(ipb1.b)

ipb2.b=peekb(ipadr.l+1)
ip2.l=calc(ipb2.b)

ipb3.b=peekb(ipadr.l+2)
ip3.l=calc(ipb3.b)

ipb4.b=peekb(ipadr.l+3)
ip4.l=calc(ipb4.b)

messagerequester("Host:"+peeks(h_name.l),"Your first IP:"+str(ip1.l)+"."+str(ip2.l)+"."+str(ip3.l)+"."+str(ip4.l),0)

End


MrVainSCL!

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/