如何将PHP脚本转换为bash

时间:2019-01-30 14:30:50

标签: php bash curl

如何将php脚本转换为bash脚本? 可以用1个curl命令来做到这一点吗?

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.eskago.pl/radio/eska-rock");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$o = curl_exec($ch);
curl_close($ch);
preg_match('/var auth = .([a-f0-9]+).*var streamUrl = .(.+)\.[am][ap][c3]\?\'/s', $o , $matches);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.eskago.pl/indexajax.php?action=radioService&start=get");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "auth=".$matches[1]."&ci=".$_SERVER['REMOTE_ADDR']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$o = curl_exec($ch);
curl_close ($ch);
header('Location: '.$matches[2].'.mp3?'.$o);

?>

1 个答案:

答案 0 :(得分:0)

我从网站获得“身份验证”

curl -j -s -L http://www.eskago.pl/radio/eska-rock| grep "var auth"|awk -F "'" '{print $2}'

接下来我将输出复制到

curl 'https://www.eskago.pl/indexajax.php?action=radioService&start=get' -H 'pragma: no-cache' -H 'origin: https://www.eskago.pl' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary53Sa7PrDT2Oc4hn1' --data-binary $'------WebKitFormBoundary53Sa7PrDT2Oc4hn1\r\nContent-Disposition: form-data; name="ci"\r\n\r\n1.1.1.1\r\n------WebKitFormBoundary53Sa7PrDT2Oc4hn1\r\nContent-Disposition: form-data; name="auth"\r\n\r\n**{MY_OUTPUT_FROM_1STEP}**\r\n------WebKitFormBoundary53Sa7PrDT2Oc4hn1--\r\n' --compressed

我有类似的东西

timestamp=1548938967&hash=58ea6f09eb72afbe1f084ab811a3fe827f8f5a3242a8eb66d3bae6cdb23de846&rip=1.1.1.1&chstr=c571ad40b34bbe1243a339f180451abf95007c2ab982c3a2943976b24466186e

但是服务器返回了HTTP错误401,需要身份验证服务器在以下命令后返回401未经授权(授权失败):

ffmpeg -i "http://waw.ic.smcdn.pl/t057-1.mp3?timestamp=1548938967&hash=58ea6f09eb72afbe1f084ab811a3fe827f8f5a3242a8eb66d3bae6cdb23de846&rip=46.229.144.34&chstr=c571ad40b34bbe1243a339f180451abf95007c2ab982c3a2943976b24466186e"

如何解决这个问题?