[ENG] 12.11. [DKSF 48.5 IU] How to Send Arbitrary SMS?

Sending SMS Messages Using an SNMP Protocol

A maximum length of random SMS messages cannot exceed 140 characters for Latin letters and 70 characters for Cyrillic ones. If there are both Latin and Cyrillic letters in the text of SMS, then the length of such SMS message cannot exceed 70 characters.

To send SMS using an SNMP protocol, there is a need to use a variable «npGsmSendSms», where a destination number and a text of an SMS message is written. To do this, see a MIB file, which can be downloaded at the page for describing a device, the tab «Files».

OID

Name

Type

Access

.1.3.6.1.4.1.25728.3800.1.3.0npGsmSendSMSDisplayStringREAD/WRITE

A format of random SMS message:

[phone_number,phone_number,...] Message

where:

phone_number – is a destination number in square brackets.

Message – is a text of a message (is separated by a space character from a destination number).

It is possible to send SMS to several destination numbers, having indicated them in square brackets separated by a comma without spaces. If there are no destination numbers chosen, an SMS will go to numbers programmed in settings of SMS notifications.

Example of Sequence of Commands for Sending a Random SMS through SNMP Using NET-SNMP Package

1. To send a random SMS, it is possible to use a specific package NET-SNMP. To do this, there is a need to download a distributive package NET-SNMP from the section Download of the website: http://net-snmp.sourceforge.net/download.html

2. After installing the package NET-SNMP, run the utility snmpset.exe from a command line. To run a command line, use a key combination «Windows+L». After a window «Execute» is opened, enter a command «cmd» and click the button «Enter». Then go to the installing directory of the utility snmpset.exe in a command line:


3. Run the utility snmpset.exe with the following parameters of a command line:

snmpset.exe -v 1 -c COMMUNITY IP OID TYPE VALUE

where:

COMMUNITY  is a specific password, which is set at the page «SETUP» of a device web interface. In NetPing devices, it is community=SWITCH on default; 

IP  is an IP address of a NetPing device, through which a random SMS message will be sent; 

OID  is an SNMP identifier of a variable «npGsmSendSms», which is used to send a random SMS message;

TYPE  is a type of written value of an SNMP identifier of a variable. Symbols of types are represented in the picture:


VALUE  is a written value, i.e. a text of an SMS message

Based on the above description, a command for sending a random SMS using the utility snmpset.exe is:

C:\Program Files (x86)\net-snmp\usr\bin>snmpset.exe -v 1 -c SWITCH 192.168.0.100 .1.3.6.1.4.1.25728.3800.1.9.0 s "[+79130000000] Hello! Test SMS!"

4. After a command is successfully executed, the next response should be received:

SNMPv2-SMI::enterprises.25728.3800.1.9.0 = STRING: "[+79130000000] Hello! Test SMS!"

Sending SMS Messages via Third-Party Web-Applications (HTTP API)

A maximum length of random SMS messages must not exceed 140 Latin characters or 70 Cyrillic characters. If there are both Latin and Cyrillic characters in the body of the SMS, then a length of such SMS message cannot exceed 70 characters.

Example of Sending a Random SMS Using a JavaScript Code

To send an SMS through a third-party web applications, there is a need to use the next JavaScript code:

var r = new XMLHttpRequest();
r.open('POST', 'http://192.168.0.100/sendsms.cgi', true, 'visor', 'ping'); // visor:ping – username and password
r.withCredentials = true;
r.send('[+79130000000] Houston, we have a problem!');

where:

192.168.0.100 – is a default IP address of a device.

visor – is a default username for connecting to a device web interface.

ping – is a default password for connecting to a device web interface.

It is possible to send an SMS to several destination numbers, having indicated them in square brackets separated by a comma without spaces. If destination numbers are not chosen, an SMS will go to the numbers programmed in the settings of SMS notifications.

If a format for data is correct, then the next JavaScript code is returned as a result:

sendsms_result('ok');

A result of sending a message does not influence a returned CGI (Common Gateway Interface) response. CGI only initiates sending a message.

Example of Sending a Random SMS Using a PowerShell Script

To send an SMS through a third-party web applications, there is a need to use the next PowerShell script:

$url = "http://192.168.137.100/sendsms.cgi"
$username = "visor"
$password = "ping"

$reqBody = "[0953345975] Тест NetPing!"

$req = [System.Net.WebRequest]::Create($url)
$req.Method = "POST";

$req.Credentials = new-object System.Net.NetworkCredential($username, $password)

$Body = [System.Text.Encoding]::UTF8.GetBytes($reqBody);

$stream = $req.GetRequestStream();
$stream.Write($Body, 0, $Body.Length);

$stream.Flush();
$stream.Close();

$resp = $req.GetResponse().GetResponseStream()
$resp.Close() 

where:

$url is a variable, which sets an IP address of a NetPing device and a script for sending random SMS messages.

$username – is a variable, which sets a username for authorization on a NetPing device.

$password – is a variable, which sets a password for authorization on a NetPing device.

$reqBody – is a variable, which sets a destination number in square brackets and a text of an SMS message (is separated by a space character from a destination number). It is possible to send SMS to several destination numbers, having indicated them in square brackets separated by a comma without spaces.