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
get ip address from UDP
Page 1 of 15 Replies - 313 Views - Last Post: 24 September 2012 - 01:35 PM
Replies To: get ip address from UDP
#2
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/
http://www.binarytid...sniffer-in-php/
#3
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.
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
#4
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
#5
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
SOL_UDP should work instead of SOL_TCP
#6
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.....
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|