Wednesday, June 16, 2010

How to get the IP address of local area connection in C#


NetworkInterface[] NInterfaces = null;
NInterfaces = NetworkInterface.GetAllNetworkInterfaces;

foreach(NetworkInterface NInterface in NInterfaces) {
if(NInterface.Name == "Local Area Connection") {
foreach(IPAddressInformation Info in NInterface.GetIPProperties().UnicastAddresses) {
if(Info.Address.AddressFamily.ToString == "InterNetwork") {
MessageBox.Show("IP Address: " + Info.Address.ToString());
}
}
}
}


You can also use this function to get the local IPv4 IP when you have IPv6 enabled:


private IPAddress GetIPAddress() {

System.Net.IPAddress IP = null;

foreach (IPAddress localIP in System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).AddressList) {
if (localIP.AddressFamily == AddressFamily.InterNetwork & IP == null) {
IP = localIP;
}
}

return IP;

}

Monday, May 3, 2010

You know you have been programming too much when...

You know you have been programming too much when you start ending your sentences with a semicolon instead of a period;

Friday, April 16, 2010

Rename a VPN Connection in Windows 7

Question: How do I rename a VPN connection in Windows 7? There’s no option to rename it in the Network and Sharing Center or on the taskbar.

This question is asked a lot because there is currently no intuitive way to quickly change the name of a VPN connection in Windows 7.

Answer: Click (left mouse button) the connection icon on the task tray then click "Open Network and Sharing Center" then click "Change adapter settings" on the left of that window then right click the connection and click "Rename".

To recap:
"Network and Sharing Center" -> "Change adapter settings" -> "Rename"

And that is how you rename your VPN connection in Windows 7.

Tuesday, April 6, 2010

jQuery Plug-in I Wrote For Doing Web Form Textfield Placeholders

Here is a very useful jQuery plug-in I wrote to show placeholders in input text fields and input password fields. Great for a Facebook style log-in form.

Download it here: Password Compatible jQuery Placeholder

Apache HTTPD Virtual Hosting Setup in Step By Step Instructions

A buddy of mine is new to server administration and one of the first things I am going to show him since he is a web developer is how to setup a virtual host in Apache on CentOS 5 allowing you to run multiple web sites on a single IP address. Read the steps carefully and take your time if this is your first time doing this, it is a simple task that can easily go wrong if you rush it.


  1. Add your server IP to GoDaddy or other domain registrar's DNS settings.
    For GoDaddy this is located by navigating to Domain Manager -> Your domain -> Total DNS Control then editing the "A (Host)" record.
  2. Login to your server using putty.exe or some other SSH client.


  3. Type:
    ls /var/www
    Then look to see if there is currently a folder named "vhosts", if there isn't then type:
    mkdir /var/www/vhosts
    Next add a domain by typing:
    mkdir /var/www/vhosts/www.yournewdomain.com
    Then to add a logging directory type:
    mkdir /var/www/vhosts/www.yournewdomain.com/logs
    Then to add an error log file type:
    touch /var/www/vhosts/www.yournewdomain.com/logs/error-log
    Then to give apache permissions to the logging folder type:
    chown -R apache:apache /var/www/vhosts/www.yournewdomain.com/logs


  4. Type:
    vi /etc/httpd/conf/httpd.conf
    Then hold the "Page Down" key to scroll to the very bottom of the file and then type:
    $a
    Then press the enter key and enter the following lines:

    <VirtualHost *:80>
    ServerAdmin support@yournewdomain.com
    DocumentRoot /var/www/vhosts/www.yournewdomain.com
    ServerName www.yournewdomain.com
    ServerAlias yournewdomain.com
    ErrorLog /var/www/vhosts/www.yournewdomain.com/logs/error-log
    </VirtualHost>
    <Directory /var/www/vhosts/www.yournewdomain.com>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    </Directory>

    And then navigate around using the arrow keys and replace all instances of "yournewdomain" with your new domain name. When "-- INSERT --" shows in the lower left corner of the screen you are in edit mode, to enter edit mode you hit "i" or "a", to exit edit mode hit ESC. When in edit mode keystrokes are inserted into the document, when not in edit mode keystrokes are interpreted as commands. Always be aware if you are in edit mode or not.

    You are done editing so hit ESC to exit edit mode.
    When everything looks right then type the following to save and exit (when out of INSERT mode)
    :wq
    If you made a mistake then type:
    :e!
    This series of keystrokes will undo all changes in vi so you can start your edits over.


  5. Restart apache by typing:
    /sbin/service httpd restart


  6. To setup vsftpd (FTP server) to go to the vhosts folder on login then create a ftp user by typing the following command:

    adduser wwwftp -d /var/www/vhosts -M -p PASSWORD_FOR_USER_HERE -s /sbin/nologin

    And you are done. Use FTP with the user "wwwftp" and the password you set to upload your website files to /var/www/vhosts/www.yournewdomain.com/

Wednesday, March 31, 2010

Use mysqldump to copy tables from one schema to another

The following command is great for copying tables from one schema to another within the same MySQL database:
mysqldump -u DB_USERNAME_HERE --password="DB_PASSWORD_HERE" --opt SCHEMA1_NAME_HERE TABLE_NAME_HERE | mysql -u root -p SCHEMA2_NAME_HERE
Be aware that this will overwrite existing tables and data which is usually exactly what you want.
To copy to a schema on a different system:
mysqldump -h HOST_IP_HERE -u DB_USERNAME_HERE --password="DB_PASSWORD_HERE" --opt SCHEMA1_NAME_HERE TABLE_NAME_HERE | mysql -u root -p SCHEMA2_NAME_HERE

Find all files with a specific extension and delete them under Linux or Unix

This will search the current directory and recursively look through every folder under the current directory for files with the extension .gz and delete them.

find . -type f -name "*.gz" -exec rm -f {} \;