I have this code to send a packet in PHP, and I wanted to know how to do it in perl, I have tried sending via hex data, but it is not working. Here is the PHP code:
$sIPAddr = "37.221.175.211";
$iPort = 7777;
$sPacket = "";
$aIPAddr = explode('.', $sIPAddr);
$sPacket .= "SAMP";
$sPacket .= chr($aIPAddr[0]);
$sPacket .= chr($aIPAddr[1]);
$sPacket .= chr($aIPAddr[2]);
$sPacket .= chr($aIPAddr[3]);
$sPacket .= chr($iPort & 0xFF);
$sPacket .= chr($iPort >> 8 & 0xFF);
$sPacket .= 'c';
$rSocket = fsockopen('udp://'.$sIPAddr, $iPort, $iError, $sError, 2);
fwrite($rSocket, $sPacket);
fclose($rSocket);
How would I go about doing this in Perl? I want to use a raw socket as well to send it.
This is what I tried, but the server is not replying to it, which makes me think that the data is corrupted somewhere:
$packet = Net::RawIP->new({
ip => {
saddr => $saddr,
daddr => $dest,
},
udp => {
source => $rsport,
dest => $port,
data => "\x53\x41\x4d\x50\x25\xdd\xaf\xd3\x61\x1e\x63", # this is the data from the PHP file in HEX
},
});
$packet->send;
#, not//. Please do not mock the code in here, but post the real code. Remove stuff you do not like us to see, but try to make it compile please.