📜 ⬆️ ⬇️

Verification of Kyivstar modem account in Linux

Inspired by this topic. One day I had a move to a new place of residence and I urgently needed the Internet. Watching a Kyivstar ad for a modem for UAH 199, I purchased this kit. Setup in Ubuntu via NetworkManager did not require any effort. But I did not have enough money to check the account (not through the browser). I present to you a script that helped me solve this.



<?php

function decodePDU($ in ) {
$b = 0; $d = 0;
$ out = "" ;
foreach (str_split($ in , 2) as $ss) {
$ byte = hexdec($ss);
$c = (($ byte & ((1 << 7-$d)-1)) << $d) | $b;
$b = $ byte >> (7-$d);
$ out .= chr($c);
$d++;
if ($d == 7) {
$ out .= chr($b);
$d = 0; $b = 0;
}
}
return $ out ;
}

function encodePDU($ in ) {
$ out = "" ;
for ($i = 0; $i < strlen($ in ); $i++) {
$t = $i%8+1;
if ($t == 8)
continue ;
$c = ord($ in [$i])>>($i%8);
$oc = $c;
$b = ord($ in [$i+1]) & ((1 << $t)-1);
$c = ($b << (8-$t)) | $c;
$ out .= strtoupper(str_pad(dechex($c), 2, '0' , STR_PAD_LEFT));
}
return $ out ;
}

if (!isset($argv) || !$argv[1]){
die( "Neet number of service. Sample: <script>.php *111#\n" );
}

$number = $argv[1];

print "Number of service: $number \n" ;

$f = fopen ( "/dev/ttyUSB2" , "rw+" );
fputs($f, "AT+CUSD=1," .encodePDU($number). ",15\r\n" );

while ($s = fgets($f)) {
if (substr($s, 0, 5) == "+CUSD" ) {
$s = decodePDU(substr(trim($s), 10, -3));
echo $s. "\n" ;
if (strpos($s, "1 - Dalee" ) !== false ) {
fputs($f, "AT+CUSD=1," .encodePDU( "1" ). ",15\r\n" );
}
else
break ;
}
}

fclose($f);

?>


* This source code was highlighted with Source Code Highlighter .

')
Example of use:

$ php huawei_e1550.php *111#
Number of service: *111#
Na rahunku: 9.62 grn. Nomer die do 15/06/11. Bonusy: 0.00 grn; 0.0 Kbytes
$ php huawei_e1550.php *121#
Number of service: *121#
Paket Vil'nyj Internet: na rahunku 0.000 Mb, termin dii do 01.01.0001


Perhaps the script is suitable not only for Kyivstar modem (for others it was not tested).
I also want to note that in Ubuntu 10.4 in order for the modem to work in modem mode (and not as a USB flash drive), I’ll need to install the usb-modeswitch package .

Thank you all for your attention.

Source: https://habr.com/ru/post/98837/


All Articles