Author Topic: Returning User's IP  (Read 4917 times)

Offline CptnRoughnight

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
Returning User's IP
« on: 2013-Nov-19 »
Hi folks,

need some help  :)

I have a raspberry pi. This is my server. I need a function that returns me the IP address of the user.
User connects to server and the server sends the IP of the user back to the user. How does it work?

I tried it with NetGetIP $, but that just gives me the IP address on my network (192 172 .....)
 :doubt:


Es ist kein Mond....

A young band from Thuringia with a lot of potential :
http://youtu.be/diMBlNspsD8

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Returning User's IP
« Reply #1 on: 2013-Nov-19 »
You are talking about the external IP. Your computer has no clue what this is, you need to ask an external server for the originating IP. See services like "whatismyip.com" and similar. Also easy to do with a PHP script. Should be a post here on the boards how to do it. Let us know if you need more help with it :-)

Offline CptnRoughnight

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
Re: Returning User's IP
« Reply #2 on: 2013-Nov-19 »
You mean this thread: http://www.glbasic.com/forum/index.php?topic=5400.0 ?

This one I tried, but the service is not available. How do I call another service in this way, I do not know, I would not actually.

Is there a way with the NET commands, as a server to determine the IP address of the user? That would solve my problem as I had imagined.
Es ist kein Mond....

A young band from Thuringia with a lot of potential :
http://youtu.be/diMBlNspsD8

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Returning User's IP
« Reply #3 on: 2013-Nov-19 »
Your Server can easily know the IP of the clients that connected to it, SOCK_TCPACCEPT returns the IP of an client every time a client joins (watch 2nd parameter, its byref/a pointer), so you can simply store it somewhere and return it later. Im not sure if you can do the same with the NET_... commands, havent used them in ages, SOCK_...s are way better and more powerful.

Maybe you want to have a look at my libNET for some inspiration how to do socket work.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline CptnRoughnight

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
Re: Returning User's IP
« Reply #4 on: 2013-Nov-19 »
Thank you!


I'll look at it! The sockets have not tried, but it's apparently a good solution!

 I will report on the success or failure! ;)
Es ist kein Mond....

A young band from Thuringia with a lot of potential :
http://youtu.be/diMBlNspsD8

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Returning User's IP
« Reply #5 on: 2013-Nov-19 »
Oh, kanonet, that was just what I was about to look for tonight, thanks! :-)
Can it do UDP broadcast too?
Some usage examples could be useful too, I'm very rusty with glbasic types...

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Returning User's IP
« Reply #6 on: 2013-Nov-19 »
No its only designed for TCP. And important features like automatic syncing variables etc got never finished/added (will come... sometimes.. in the future...). But it is working and can give you a start at Sock-commands.
No real test project, but should be easy to use. Here is an very basic example how to connect (and also how to send/receive messages), sorry its a bit confusing, since its only one of my test projects, no intended tutorial:
Code: (glbasic) [Select]
// --------------------------------- //
// Project: Server
// Start: Saturday, October 01, 2011
// IDE Version: 10.118
// Autor: Kanonet

ALLOWESCAPE FALSE
AUTOPAUSE FALSE

STDOUT "  (1) Server oder (2) Client?\n"
GLOBAL sel%
sel = STDIN$()

IF sel=1
GLOBAL server AS TNetServer
server.Start(34111)
ELSEIF sel=2
GLOBAL client AS TNetClient
client.Join("",34111)
client.SendLogIn("CDK","a", TRUE)
LOCAL l%
REPEAT
l=client.LogInReply()

IF l=-4
client.SendLogIn("CDK","a")
ELSEIF l<0
END
ENDIF

SLEEP 40
UNTIL l=1
ELSE
STDOUT "Eingabe ung├╝ltig."
END
ENDIF

LOCAL key$
REPEAT
IF sel=1
server.Update()
// FOREACH p IN server.player[] // for each connected player = logged in client
// FOREACH m$ IN p.channel[chan_num%].msg$[]
// // now you can prozess each message in channel chan_num%
// NEXT
// p.ChannelSend(chan_num%, "test message from server") // send something to each player on channel 0
// NEXT
ELSE
client.Update()
// FOREACH m$ IN client.channel[chan_num%].msg$[]
// // now you can prozess all messages in channel chan_num%
// NEXT
// client.ChannelSend(chan_num%, "test message from client") // send something to the server
ENDIF
SLEEP 40

//
//  // watch ESC key to exit program
// key$=INKEY$()
// IF key$=""
// BREAK
// ENDIF
UNTIL FALSE

END

FUNCTION log%: code%, msg$, ip$=""
IF ip$ THEN msg$ = msg$+" "+ip$
STDOUT PLATFORMINFO$("TIME")+"  "+code+"   "+msg$+"\n"
ENDFUNCTION

FUNCTION PlayerJoined%: num%
server.player[num%].ChannelOpen( 0 ) // automatically open channel 0 for each player that joined
ENDFUNCTION

SUB GLB_ON_QUIT:
IF sel=1
server.Quit()
ELSE
client.Quit()
ENDIF
ENDSUB

FUNCTION ServerTerminated:
SLEEP 10000
ENDFUNCTION
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Returning User's IP
« Reply #7 on: 2013-Nov-19 »
Perfekt, thanks! I just need UDP to find the server so can easily hack something together. It's just a small project.

Offline spicypixel

  • Prof. Inline
  • *****
  • Posts: 646
  • Pixel Artist
    • View Profile
    • SpicyPixel.net
Re: Returning User's IP
« Reply #8 on: 2013-Nov-20 »
I put this online ages ago for people to query to get the real IP
Code: (glbasic) [Select]
http://ip.spicypixel.net/
http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1137
    • View Profile
    • My GLBasic code archiv
Re: Returning User's IP
« Reply #9 on: 2013-Nov-20 »
No its only designed for TCP. ....

directly from the online GLB-manual:     sock% = SOCK_UDPOPEN(port%)
Yes I know?
But I think Morus question was if my libNET does support UDP and so I answered it does not. Or did I understand something wrong?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1793
    • View Profile
    • Homepage
Re: Returning User's IP
« Reply #10 on: 2013-Nov-20 »
No you are correct, kanonet.

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: Returning User's IP
« Reply #11 on: 2013-Nov-22 »
I have a raspberry pi. This is my server.

Cool and what does the server do, I wonder?

Offline CptnRoughnight

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
Re: Returning User's IP
« Reply #12 on: 2013-Nov-22 »
The Rapsberry Pi is used as a server for my games.

This idea I wanted to implement for competition (Crap Game Competition 2013), but I've not enough time i guess.

I have many other ideas for which the Pi is suitable as a server.

Maybe i will learn html/css/php to write a homepage by myself! ;)
Es ist kein Mond....

A young band from Thuringia with a lot of potential :
http://youtu.be/diMBlNspsD8

Offline matchy

  • Prof. Inline
  • *****
  • Posts: 1545
    • View Profile
Re: Returning User's IP
« Reply #13 on: 2013-Nov-23 »
What sort of games? I have tried many server and client games. I've also had GLB as a web server!

Offline CptnRoughnight

  • Mr. Polyvector
  • ***
  • Posts: 114
    • View Profile
AW: Returning User's IP
« Reply #14 on: 2013-Nov-23 »
First simple games with high score management. But I have ideas for a kind of online game. I'll play around a bit with the possibilities once I have fully understood the network functionality ;)
Es ist kein Mond....

A young band from Thuringia with a lot of potential :
http://youtu.be/diMBlNspsD8