5 Replies - 856 Views - Last Post: 24 September 2012 - 01:35 PM Rate Topic: -----

#1 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

get ip address from UDP

Posted 24 September 2012 - 12:47 PM

Hello, I have created a java program that sends a UDP packet to my server. Using wireshark, I can see this UDP packet is being received. I want to use php to be able to get the source ip address of this UDP packet. I have no idea if this is possible through php? I know I can create a socket server, but can it get the source ip address and source port somehow? Essentially I want to log all UDP packets that are being sent to a specific port. Off topic as well, if this is possible through linux to dump the UDP packets with their source ip and port that would work as well for me.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: get ip address from UDP

#2 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: get ip address from UDP

Posted 24 September 2012 - 01:00 PM

I thought it was possible so I googled and this is what I found, a php packet sniffer. I think this is what you need so have a look.

http://www.binarytid...sniffer-in-php/
Was This Post Helpful? 0
  • +
  • -

#3 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: get ip address from UDP

Posted 24 September 2012 - 01:07 PM

i tired this and kept getting this error, couldn't figure it out. I changed the socket_create to be UDP instead of RAW.
Deprecated: Call-time pass-by-reference has been deprecated in C:\xampp\htdocs\udp.php on line 18
Could not create socket : [10043] The requested protocol has not been configured into the system, or no implementation for it exists.

This post has been edited by polska03: 24 September 2012 - 01:11 PM

Was This Post Helpful? 0
  • +
  • -

#4 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: get ip address from UDP

Posted 24 September 2012 - 01:25 PM

I found this online for TCP connections. The problem is it is for TCP connections so things such as socket_listen won't work. If I can modify this somehow for UDP, and to be able to read the source ip and port that would be great.

$host = "111.111.111.111";
$port = 9213;

set_time_limit(0);

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket");

$result = socket_bind($socket, $host, $port) or die("Could not bind to socket");  

$result = socket_listen($socket, 3) or die("Could not set up socket listener");

$spawn = socket_accept($socket) or die("Could not accept incoming connection");

$input = socket_read($spawn, 1024) or die("Could not read input");

$input = trim($input);

$output = $input;
socket_write($spawn, $output, strlen ($output)) or die("Could not write output");

socket_close($spawn);
socket_close($socket);


This post has been edited by polska03: 24 September 2012 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#5 nightscream  Icon User is offline

  • D.I.C Head

Reputation: 19
  • View blog
  • Posts: 237
  • Joined: 04-December 08

Re: get ip address from UDP

Posted 24 September 2012 - 01:25 PM

you should replace &$buf to $buf.
SOL_UDP should work instead of SOL_TCP
Was This Post Helpful? 0
  • +
  • -

#6 polska03  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 302
  • Joined: 28-November 09

Re: get ip address from UDP

Posted 24 September 2012 - 01:35 PM

Now it just says starting sniffing...... and so I sent the UDP packet (saw on Wirehshark it was sent) and the page keeps saying starting sniffing.....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1