Calculate Passive FTP Data Port

ftp data port
When communicating over FTP, two ports are used, one for commands and the other for data.

Here’s how to calculate the ftp data port:

227 Entering Passive Mode (10,10,1,11,19,15)

10,10,1,11 is the server’s TCP/IP address.

19,15 is the port that the server is telling the client to use during the data transfer. To calculate this port, use the formula: (first value x 256) + second value.

This example has a value of (19 x 256) + 15 = 4879.

So the data port for this FTP connection will be port number4879.

See also: RFC 959 – File Transfer Protocol

PHP Class – OOP

A PHP Class can be used for several things, but at the most basic level, you’ll use classes to “organize and deal with like-minded data”. Here’s what I mean by “organizing like-minded data”. First, start with unorganized data.

<?php
$customer_name;
$item_name;
$item_price;
$customer_address;
$item_qty;
$item_total;
?>

Now to organize the data into PHP classes:

<?php
class Customer {
$name; // same as $customer_name
$address; // same as $customer_address
}

class Item {
$name; // same as $item_name
$price; // same as $item_price
$qty; // same as $item_qty
$total; // same as $item_total
}
?>

Now here’s what I mean by “dealing” with the data. Note: The data is already organized, so that in itself makes writing new functions extremely easy.

<?php
class Customer {
public $name, $address; // the data for this class…

// function to deal with user-input / validation
// function to build string for output
// function to write -> database
// function to read <- database // etc, etc } class Item { public $name, $price, $qty, $total; // the data for this class... // function to calculate total // function to format numbers // function to deal with user-input / validation // function to build string for output // function to write -> database
// function to read <- database // etc, etc } ?> Imagination that each function you write only calls the bits of data in that class. Some functions may access all the data, while other functions may only access one piece of data. If each function revolves around the data inside, then you have created a good class.

Nbtstat

Nbtstat is designed to help troubleshoot NetBIOS name resolution problems. When a network is functioning normally, NetBIOS over TCP/IP (NetBT) resolves NetBIOS names to IP addresses. It does this through several options for NetBIOS name resolution, including local cache lookup, WINS server query, broadcast, LMHOSTS lookup, Hosts lookup, and DNS server query.

The nbtstat – a < name > or nbtstat – a < IP address > command performs a NetBIOS adapter status command on the computer name specified by < name >.

The nbtstat – c option shows the contents of the NetBIOS name cache, which contains NetBIOS name-to-IP address mappings.

nbtstat -n displays the names that have been registered locally on the system by NetBIOS applications such as the server and redirector.

Ways to validate Phone Numbers in C#

using System;
using System.Text.RegularExpressions;

class RegexSubstitution
{
   public static void Main()
   {
      string text = "124";

      if ( !Regex.Match(text,@"^[1-9]\d{2}-[1-9]\d{2}-\d{4}$" ).Success )
      {
         Console.WriteLine( "Invalid phone number");
      }   
   }
}

Validate Phone Number

public bool IsValidUSPhone(string number)
{
    return Regex.IsMatch(number, @"\(\d{3}\)\s\d{3}-\d{4}");
}

Matching and Grouping Regular Expressions using Regex in C#