2016-06-24 3 views
2

私は長い間、Huawei E3131でコマンドラインでsmsを送信する方法と、DebianベースのLinuxシステムでHiLinkからインターネットを検索しました。それらのすべては働かなかった。それは、ソフトウェアの更新があったようです。Huawei E3131でコマンドラインを使ってSMSを受信し、DebianシステムでHiLink


HiLinkは私に次のバージョンを示しています

  • デバイス名:E3131
  • ハードウェアバージョン:CU1E3131IM
  • ソフトウェアバージョン:22.521.23.00.00
  • ウェブを - フロントエンド - バージョン:17.100.08.00.03

質問:E3131でDebianベースのLinuxシステムでコマンドラインでSMSを送受信する方法は?


There is a follow up question for setting up the hardware on a headless system on superuser

答えて

7

3の手順が必要です:

  1. セッションID
  2. はトークン
  3. センド/ SMSを受信
をゲット

ステップ1 - 私は自分のシェルスクリプトで次のコマンドを使用してセッションIDを取得するためのセッションID

を取得:

#!/bin/bash 

curl -b session.txt -c session.txt http://192.168.8.1/html/index.html > /dev/null 2>&1 

ステップ2 - ゲットトークン

トークンを取得するには、次のコマンドを使用します。これは、独自のシェルスクリプトでも使用します。

#!/bin/bash 

TOKEN=$(curl -s -b session.txt -c session.txt http://192.168.8.1/html/smsinbox.html) 
TOKEN=$(echo $TOKEN | cut -d'"' -f 10) 

echo $TOKEN > token.txt 

ステップ3パートA - SMS送信最後に

他の2つのスクリプト呼び出し、SMS、送信するための第三のシェルスクリプト:

#!/bin/bash 

NUMBER=$1 
MESSAGE=$2 

./session.sh 
./token.sh 

LENGTH=${#MESSAGE} 
TIME=$(date +"%Y-%m-%d %T") 
TOKEN=$(<token.txt) 

SMS="<request><Index>-1</Index><Phones><Phone>$NUMBER</Phone></Phones><Sca/><Content>$MESSAGE</Content><Length>$LENGTH</Length><Reserved>1</Reserved><Date>$TIME</Date></request>" 

echo $SMS 

curl -v -b session.txt -c session.txt -H "X-Requested-With: XMLHttpRequest" --data "$SMS" http://192.168.8.1/api/sms/send-sms --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml" 

使い方があるの:


ステップ3パートB - 受信SMS

そして最後の未読SMSを受信するための(下盛されていない場合、または、最後の読み取りSMS)私は次のスクリプトを使用します。

#!/bin/bash 

./session.sh 
./token.sh 

TOKEN=$(<token.txt) 

DATA="<request><PageIndex>1</PageIndex><ReadCount>1</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" 

curl -b session.txt -c session.txt -H "X-Requested-With: XMLHttpRequest" --data "$DATA" http://192.168.8.1/api/sms/sms-list --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml" 

これはあまり良いコーディングではないかもしれませんが、うまくいきます。

+1

これもe3531のために働くかもしれません – Peters

+0

ありがとう、非常に! – valentt

1

Peterは本当にうまく説明しましたが、私はシングルスクリプトが好きですが、Debianの代わりにOpenWrtルータでも使用します。だからここ

は、SMS送信のための私のバージョンです:

#!/bin/sh 

RESPONSE=`curl -s -X GET http://192.168.8.1/api/webserver/SesTokInfo` 
COOKIE=`echo "$RESPONSE"| grep SessionID=| cut -b 10-147` 
TOKEN=`echo "$RESPONSE"| grep TokInfo| cut -b 10-41` 
NUMBER=$1 
SMS=$2 
DATA="<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>$NUMBER</Phone></Phones><Sca></Sca><Content>$SMS</Content><Length>11</Length><Reserved>1</Reserved><Date>-1</Date></request>" 

curl -v http://192.168.8.1/api/sms/send-sms \ 
-H "Cookie: $COOKIE" -H "__RequestVerificationToken: $TOKEN" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \ 
--data $DATA 

をそしてここで、最後の3つのSMSメッセージを読み取るためのスクリプトです:

:私は私のHUAWEIのE3276のためのPythonスクリプトを作っ
#!/bin/sh 

RESPONSE=`curl -s -X GET http://192.168.8.1/api/webserver/SesTokInfo` 
COOKIE=`echo "$RESPONSE"| grep SessionID=| cut -b 10-147` 
TOKEN=`echo "$RESPONSE"| grep TokInfo| cut -b 10-41` 
DATA="<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>" 

curl -b $COOKIE -c $COOKIE -H "X-Requested-With: XMLHttpRequest" --data "$DATA" http://192.168.8.1/api/sms/sms-list --header "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml" 
0

import requests, sys 
import xml.etree.ElementTree as ET 

msg = "From python" 
phone = "PHONE_NUMBER" #To fill 
ip = "192.168.1.1" #Dongle ip 

#Get token 
r = requests.get("http://%s/api/webserver/token" % ip) 
root = ET.fromstring(r.content) 
token = root[0].text 
print "token", token 

#Send sms 
headers = { "__RequestVerificationToken": token, "Content-Type": "text/xml" } 
data = "<request><Index>-1</Index><Phones><Phone>%s</Phone></Phones><Sca/><Content>%s</Content><Length>%d</Length><Reserved>1</Reserved><Date>$TIME</Date></request>" % (phone, msg, len(msg)) 
r = requests.post("http://%s/api/sms/send-sms" % ip, data=data, headers=headers) 
print "send-sms", r.headers, r.content 
関連する問題