Thursday, October 24, 2013

[VB.NET] OpenVPN GUI 101: TAP Adapter Detection

They say there are other ways to check whether you have TAP driver(s) installed in your system but since I don't know what they are I'll just show you the way that I know :p

A little intro. If you know how to use the regedit(Registry Editor) you can browse this key "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\NET". If the key "NET" doesn't exist that means you don't have TAP driver installed else you will see all the virtual network adapters available or installed in your system. They are divided in subkeys starting from 0000, 0001, 0002 and so on. That's our meal.

So we now know where to check the adapters manually in the registry, now let's start building our code to check it programmatically. First we need to import the following so that we can use the Registry Class which we will be needing to access the registry key mentioned above.

Imports Microsoft.Win32

Then the nice part...

'Variable declaration
Dim regTap As RegistryKey
Dim tap0901 As Boolean = False
Dim regTmp As RegistryKey
Dim regTmpVal As String

'Let's try to open the "NET" key
regTap = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\Root\\NET", False)
'Does "NET" key exist?
If regTap Is Nothing Then
  'If it doesn't then...
  GoTo NoTap
Else
'If it does then...
'Each virtual adapters are placed inside a key and are named starting from 0000(0001,0002, on so on). Let's read each subkey inside "NET" key so we can check if there's a TAP installed.
For Each x As String In regTap .GetSubKeyNames
  'Open each subkey.
  regTmp = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\Root\\NET\\" & x.Trim, False)
  'Our main interest is "HardwareID" the value of it will serve as our keyword if the subkey being checked is a TAP driver or not
  regTmpVal = regTmp.GetValue("HardwareID")(0)

  'tap0901 by default is false
  If tap0901 = False Then
    'if "HardwareID" is equals to "tap0901" which is the ID of TAP then set our v     ariable tap0901 to true :)
    If regTmpVal = "tap0901" Then
      tap0901 = True
    End If
  End If
  regTmpVal = ""
Next
End If
NoTap:
'Some codes here

FIN :D

Basic Modem Communication (Initializing a ZTE MF627 Modem) Part II: The AT Commands

Now that we know how to open the modem port the next thing we need to do is to initialize it by sending the proper AT commands to the modem. I sniffed some commands from my modem I'm just not sure if all of them are needed but I'm still posting all of them anyway :D

This is the AT commands sequence I'm using. You need to send these commands(from top to bottom) one by one with atleast 200 milliseconds interval.
AT+ZUSIM=?
AT+CPBS="SM"
AT+CPBR=?
AT+CPBS="SM"
AT+CPMS="SM","SM","
AT+CGSN
AT
AT+ZSEC=?
AT+ZOPRT?
AT+GMR
AT+CGSN
AT+CGMM
AT+GMR
AT+CGSN
AT+CGMM
AT+CPIN?
AT+ZECC?
AT+ZSEC?
AT+ZSTART
ATE0
AT+ZPAS?
AT+ZDON?
AT+CSQ
AT+ZDON?
AT+ZPAS?
AT+CLCK="SC"
AT+CPMS=?
AT+CLVL?
AT+CGDCONT=1,"IP","internet",,0,0
AT+ZBANDI?
AT+CSCA?
AT+ZSMSD?
AT+ZSNT?
AT+ZBANDI?
AT+ZUSIM=?
AT+CPBS="SM"
AT+CPBR=?
AT+ZCPBR=?
AT+CPBR=1,20
AT+CPBR=21,40
AT+CPBR=41,60
AT+CPBR=61,80
AT+CPBR=81,100
AT+CPBR=101,120
AT+CPBR=121,140
AT+CPBR=141,160
AT+CPBR=161,180
AT+CPBR=181,200
AT+CPBR=201,220
AT+CPBR=221,240
AT+CPBR=241,250
AT+CSCS="IRA"
AT+CLVL?
AT+CLIP=1
AT+CMGF=0
AT+CNMI=3,1,0,2,0
AT+CSQ
AT+ZDON?
AT+ZPAS?
AT+CPMS="ME","ME",""
AT+CMGL=4
AT+CPMS="SM","SM",""
AT+CMGL=4
AT+CSQ
AT+ZDON?
AT+ZPAS?
AT+CSQ
AT+ZDON?
AT+ZPAS?
AT+CSQ
AT+ZDON?
AT+ZPAS?
AT+ZCSPOWER
After sending these commands successfully you can now use your modem to do other tasks like send/receive sms, phonebook, etc. To check if our modem really did initialize let's try getting the signal strength.
AT+CSQ
AT+ZDON?
AT+ZDON?
Sending these commands to the modem will give you the signal strength in this format "+CSQ:18,99" where 18 is the signal strength. The signal strength/quality value range from 2-30(30 = excellent quality) and has a corresponding dBm value. In my example 18 means -77 dBm(30 = -53 dBm). You can use the following table as reference.

Value RSSI dBm Condition
2 -109 Marginal
3 -107 Marginal
4 -105 Marginal
5 -103 Marginal
6 -101 Marginal
7 -99 Marginal
8 -97 Marginal
9 -95 Marginal
10 -93 OK
11 -91 OK
12 -89 OK
13 -87 OK
14 -85 OK
15 -83 Good
16 -81 Good
17 -79 Good
18 -77 Good
19 -75 Good
20 -73 Excellent
21 -71 Excellent
22 -69 Excellent
23 -67 Excellent
24 -65 Excellent
25 -63 Excellent
26 -61 Excellent
27 -59 Excellent
28 -57 Excellent
29 -55 Excellent
30 -53 Excellent

If your modem respond to your signal query that means you're good to go. Just parse the +CSQ response using regex and get only the signal quality then you can forward it to a progress bar or where ever you want.

TO BE CONTINUED AGAIN...

PS: I know I suck at explaining and I'm not good at english either :D I just wanted to put something in my blog just like any other blogger lol

Wednesday, October 23, 2013

[VB.NET] Basic Modem Communication (Initializing a ZTE MF627 Modem)

This article is based on my unfinished(again) project called the "Project Dashboard Clone" :D. The project aims to make a modem dashboard to be a lot simpler, removing most features of an official dashboard so I/you can include this module to your project that is related to modem, internet, vpn etc. Unfortunately I stopped the project because I only have a ZTE modem and my actual plan was to release a universal dashboard that supports ZTE and Huawei modems which are the only available devices that currently distributed here in my country by the telecom companies.

Temporarily I will only give minor codes and concept. Other codes are to follow for I'm not the one who wrote them.

Ok let's start!

First rule. You can't communicate with the modem or it doesn't get detected unless the CD drive that is loaded at first insert of the device gets ejected.

Dim CDROMDeviceQuery As New SelectQuery("Win32_CDROMDrive")
Dim CDROMDeviceSearch As New ManagementObjectSearcher(CDROMDeviceQuery)
Dim CDROMDeviceInfo As ManagementObject
For Each CDROMDeviceInfo In CDROMDeviceSearch.Get()
 If CDROMDeviceInfo("caption").ToString.Contains("ZTE") Then
   Dim tst As New VolumeEject
   tst.Eject(CDROMDeviceInfo("drive").ToString.Replace(":", ""))
 End If
Next

The code above will try to enumerate all available DVD/CD ROM drives in your computer and search for the ZTE CD drive, then ejects it. After it ejects the drive, the modem will then be detected and you can start using it.

Now that the modem is available and ready we will now try to initialize it. In this example I'm going to put the port number manually but of course the best way is to enumerate all ports especially if you have multiple modems installed.

Dim serialport As New IO.Ports.SerialPort
With serialport
 .PortName = "COM14"
 .BaudRate = 96000
 .Parity = Parity.None
 .DataBits = 8
 .StopBits = StopBits.One
 .Handshake = Handshake.RequestToSend
 .ReadTimeout = 300
 .WriteTimeout = 300
 .Encoding = Encoding.GetEncoding("iso-8859-1")
 .DtrEnable = True
 .RtsEnable = True
 .NewLine = vbCrLf
End With
serialport.Open()

TO BE CONTINUED... LOL

Tuesday, October 22, 2013

Batch File to Executable (Batch To Exe)


(Inspired by some users from Symbianize who makes their own VPN release using batch scripts :D)

It's not actually a converter but more of a loader. This program generates an executable file(stub) with your batch script in it and run it like a standalone program. This will not give you maximum protection for your batch scripts but still, a handy app to hide your code from those damn noob leechers lol atleast give them a little challenge.

How to use:
1. Just open your bat file and that's it :D
Optional: If you want to use your own custom icon just replace the ico.ico file that is inlcluded in this release.

Download

Modified OpenVPN GUI Portable Supports Normal and Hotspot Shield Config

The title says it all. This is a modified OpenVPN GUI Portable originally made by Lukas Landis. There's actually no major changes in this version except that it supports normal and hotspot shield configs.

How to use:
1. Just add the word "ALT" for Hotspot Shield Configs (check screenshot)

Download

Tuesday, October 15, 2013

[WIP] CM OpenVPN Config Editor with Help & Syntax Highlighter

I was experimenting with this syntax highlighting thingy since last week and can't still figure out how can I improve its performance. Though it works and does what I just wanted, it starts to lag when writing more than 10 lines. I already search for some solutions and tips but they're too advance that my nose starts to bleed :D I call it quits for now lol. But I will start to work on this project again if I'm freeee! PS: If you notice the words in red it means they are already in the database and will show the corresponding help. I'm attaching the database I'm using and feel free to update it just drop me a message if you're done. I'll put your name somewhere in the app as credit if ever I plan to release it. Download Database

FreeTXT (Compilation of free SMS/Text websites)

FreeTXT is an all-in-one free text messaging app utilizing the server of some known website offering free sms like Txtmyt.org, Astigtxt.com and Magtxtonline.com. I originally made this for my personal use for there are some occasions, especially in the office that I can't let somebody see me use a browser. There are no special feature in this release. This works totally the same as the web version. DISCLAIMER: I do not own the servers used in this program and this app is not meant to replace the original web version. Download Here are original websites of the server I used. TXTMYT.ORG ASTIGTXT.COM MAGTXTONLINE.COM  

Amount to Words Converter (C#/C Sharp)

Simple code to convert a number or amount from 0 to 999,999. This was originally written in VB6(by me) but since I've been trying to learn C# lately I ported this to C# as my basic exercise. I know it's just a simple code but I'm still posting this, it might useful to someone. Here's the code:
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace CodeMonkey
{

class AmountToWords
{
    static void Main()
 {
  Console.WriteLine("Enter amount: ");
  string amnt = Console.ReadLine();
  Console.WriteLine("{0} = {1}", amnt, NumToText(amnt));
  Console.ReadKey();
 }

 static string Ones(string strNum)
 {
  string tmp = "";
  switch (strNum) {
   case "1":
    tmp = "One";
    break;
   case "2":
    tmp = "Two";
    break;
   case "3":
    tmp = "Three";
    break;
   case "4":
    tmp = "Four";
    break;
   case "5":
    tmp = "Five";
    break;
   case "6":
    tmp = "Six";
    break;
   case "7":
    tmp = "Seven";
    break;
   case "8":
    tmp = "Eight";
    break;
   case "9":
    tmp = "Nine";
    break;
   default:
    tmp = "";
    break;
  }
  return tmp;
 }

 static string Tens(string strNum)
 {
  string tmp = "";
  string tst = Convert.ToInt32(strNum).ToString();
  switch (tst) {
   case "10":
    tmp = "Ten";
    break;
   case "11":
    tmp = "Eleven";
    break;
   case "12":
    tmp = "Twelve";
    break;
   case "13":
    tmp = "Thirteen";
    break;
   case "14":
    tmp = "Fourteen";
    break;
   case "15":
    tmp = "Fifteen";
    break;
   case "16":
    tmp = "Sixteen";
    break;
   case "17":
    tmp = "Seventeen";
    break;
   case "18":
    tmp = "Eighteen";
    break;
   case "19":
    tmp = "Nineteen";
    break;
   default:
    tmp = Ones(Convert.ToInt32(strNum).ToString());
    break;
  }

  return tmp;
 }

 static string Ties(string strNum)
 {
  string tmp = "";
  string tst = Convert.ToInt32(strNum.Substring(0, 1)).ToString();
  switch (tst) {
   case "2":
    tmp = "Twenty";
    break;
   case "3":
    tmp = "Thirty";
    break;
   case "4":
    tmp = "Forty";
    break;
   case "5":
    tmp = "Fifty";
    break;
   case "6":
    tmp = "Sixty";
    break;
   case "7":
    tmp = "Seventy";
    break;
   case "8":
    tmp = "Eighty";
    break;
   case "9":
    tmp = "Ninety";
    break;
   default:
    tmp = Ones(Convert.ToInt32(strNum).ToString());
    break;
  }

  tmp = tmp + " " + Ones(strNum.Substring(1, 1));

  return tmp;
 }

 static string Hundreds(string strNum)
 {
  string tmp = "";
  if (strNum.Length == 0)
   tmp = "";
  int ln = strNum.Length;

  if (ln == 3) {
   tmp = Ones(Convert.ToString(strNum[0])) + " Hundred ";
   int twos = Convert.ToInt32(strNum.Substring(1, 2));
   if (twos > 19) {
    tmp = tmp + Ties(Convert.ToString(twos));
   } else {
    tmp = tmp + Tens(Convert.ToString(twos));
   }
  } else if (ln == 2) {
   if (Convert.ToInt32(strNum) > 19) {
    tmp = Ties(strNum);
   } else {
    tmp = Tens(strNum);
   }
  } else {
   tmp = Ones(strNum);
  }

  return tmp;
 }

 static string NumToText(string strNum)
 {
  string tmp = "";
  int iLen = 0;
  string sCents = null;
  string sCentsText = "";
  bool isCent = false;
  string _tens = null;

  strNum = strNum.Replace(",","");

  if (strNum.Contains(".")) {
   string[] spl = CustomSplit(strNum);
   sCents = spl[1];
   strNum = spl[0];
   iLen = strNum.Length;
   isCent = true;
   if (Convert.ToInt32(sCents) > 19) {
    sCentsText = Ties(sCents);
   } else {
    sCentsText = Tens(sCents);
   }
  } else {
   iLen = strNum.Length;
   strNum = Convert.ToInt32(strNum).ToString();
  }

  switch (iLen) {
   case 1:
    tmp = Ones(strNum);
    break;
   case 2:

    if (Convert.ToInt32(strNum) > 19) {
     _tens = Ties(Convert.ToInt32(strNum).ToString("D"));
    } else {
     _tens = Tens(Convert.ToInt32(strNum).ToString("D"));
    }

    tmp = _tens + " Pesos";

    if (isCent) {
     tmp = tmp + " And " + sCentsText + " Cents";
    }
    break;
   case 3:
    tmp = Hundreds(Convert.ToInt32(strNum).ToString("D")) + " Pesos";

    if (isCent) {
     tmp = tmp + " And " + sCentsText + " Cents";
    }
    break;
   case 4:
    tmp = Ones(Convert.ToInt32(strNum.Substring(0, 1)).ToString("D")) + " Thousand " + Hundreds(Convert.ToInt32(strNum.Substring(1, 3)).ToString("D")) + " Pesos";

    if (isCent) {
     tmp = tmp + " And " + sCentsText + " Cents";
    }
    break;
   case 5:

    if (Convert.ToInt32(strNum.Substring(0, 2)) > 19) {
     _tens = Ties(Convert.ToInt32(strNum.Substring(0, 2)).ToString("D"));
    } else {
     _tens = Tens(Convert.ToInt32(strNum.Substring(0, 2)).ToString("D"));
    }

    tmp = _tens + " Thousand " + Hundreds(Convert.ToInt32(strNum.Substring(2, 3)).ToString("D")) + " Pesos";

    if (isCent) {
     tmp = tmp + " And " + sCentsText + " Cents";
    }
    break;
   case 6:
    tmp = Hundreds(Convert.ToInt32(strNum.Substring(0, 3)).ToString("D")) + " Thousand " + Hundreds(Convert.ToInt32(strNum.Substring(2, 3)).ToString("D")) + " Pesos";

    if (isCent) {
     tmp = tmp + " And " + sCentsText + " Cents";
    }
    break;
  }

  return tmp;
 }

 static string[] CustomSplit(string str)
 {
  int pos = str.IndexOf(".");
  string[] tmp = new string[3];
  tmp[0] = str.Substring(0, pos);
  tmp[1] = str.Substring(pos + 1, str.Length - (tmp[0].Length + 1));
  return tmp;
 }

    }
}
  Or you can try it online via Programmr

 

Copyright 2017 Code Monkey