Windows
[VirtualBox/Linux/Windows] Copied Linux Guests Increasing eth devices
by Chuck Kozler on Jan.13, 2010, under Computers, Linux/Unix, Ubuntu, Windows
I noticed that when you copy Linux guests (VBoxManage clonevdi) and then try to use them, your ethernet device adapters keep increasing by one (eth0,eth1,eth2..etc).
This happens because the OS is looking in /etc/udev/rules.d/70-persistent-net.rules to look for the MAC address and corresponding adapter. Since the MAC address on the now new guest has been changed by VirtualBox, obviously the Guest OS can not find this MAC address. Naturally, it disables eth0 and creates eth1 with the new VirtualBox generated MAC address.
This can become quite troublesome, especially if you make a copy of a copy of a copy and so on.
I wrote a quick script to swap these MAC addresses around for you. I had to write something like this because I had to deploy about 20 Virtualized Guests and I created a base VDI to copy over and over as I needed it. I placed this script in the /root directory so I could just “su” and execute it, restart, and my address was fixed.
#!/bin/bash user=`whoami` if [ $user != "root" ]; then echo "You must be root to run this. Exiting." exit 300 fi function swapMacs { eth0_mac=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth0" | cut -d ',' -f4 | cut -d '=' -f3 | cut -d '"' -f2 | sed -e 's/:/\\\\:/g'` if [ -z $eth0_mac ]; then echo " ! MAC Address for eth0 is empty. Could not retrieve MAC from udev file." exit 100 fi eth1_mac=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth1" | cut -d ',' -f4 | cut -d '=' -f3 | cut -d '"' -f2 | sed -e 's/:/\\\\:/g'` if [ -z $eth1_mac ]; then echo " ! MAC Address for eth1 is empty. Could not retrieve MAC from udev file. ( Are you sure the line exists? )" exit 100 fi echo " * Find old mac: $eth0_mac" echo " * Replacing with: $eth1_mac" sed -i "s/$eth0_mac/$eth1_mac/g" /etc/udev/rules.d/70-persistent-net.rules if [ $? -eq 0 ]; then echo " + Successfully swapped mac addresses" echo " * Setting new udev file" new_rule=`cat /etc/udev/rules.d/70-persistent-net.rules | grep -i "eth0"` echo $new_rule > /etc/udev/rules.d/70-persistent-net.rules if [ $? -eq 0 ]; then echo " + We have successfully updated the udev file" else echo " ! Problem updating the udev file" exit 100 fi else echo " ! Problem swapping mac addresses" exit 100 fi } swapMacs
[Ubuntu\Mono\Gnome] GtkMountISO Application Release
by Chuck Kozler on Sep.27, 2009, under Computers, Home, Linux/Unix, Programming, Ubuntu, Windows
So, I guess this is my actual first application release in about 4 years since I stopped writing cheats/hacks for Counter-Strike and Counter-Strike source. You can see the video of this in action below and underneath, a link to download it from. You can find all the information you need in the readme. Please, make sure you read the readme, it will save us all a lot of time. For whatever reason, I am going to post the flow chart I made for the bash installer script. Maybe *someone* can find it useful in the future.
Sphere: Related Content[Mono/Linux] C# Shell Commands
by Chuck Kozler on Mar.24, 2009, under Computers, Home, Linux/Unix, Programming, Windows
These are some functions I have wrote recently for more or less debugging purposes. I use these functions to execute shell commands via C#. I am in no way a professional programmer so my code may seem sloppy, redundant, or plain useless to some. Thank you, but, please keep those comments to yourself.
What the function does is pretty much explained in the function definitions.
public string logfile = "debug.log"; public void writelog( string logfile, string message ) { string datetime = System.DateTime.Now.ToString(); if( !File.Exists( logfile ) ) runshellcmd( "touch " + logfile ); StreamWriter file = new StreamWriter( logfile, true ); file.WriteLine( "[ " + datetime + " ]:\n" + message + "\n" ); file.Close( ); } public int runshellcmd( string cmd ) { string[] parts = cmd.Split( ' ' ); string cmd_name = parts[ 0 ]; string arguments = ""; if( parts.Length > 1 ) for( int i = 1; i < parts.Length; i++ ) arguments += " " + parts[ i ]; Process proc = new Process( ); proc.StartInfo.FileName = cmd_name; proc.StartInfo.Arguments = arguments; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; try { if( proc.Start( ) ) { proc.WaitForExit( ); return proc.ExitCode; } else return proc.ExitCode; } catch( System.ComponentModel.Win32Exception w32e ) { writelog( logfile, w32e.Message.ToString( ) ); return proc.ExitCode; } } public string getoutput( string cmd ) { string[] parts = cmd.Split( ' ' ); string cmd_name = parts[ 0 ]; string arguments = ""; if( parts.Length > 1 ){ for( int i = 1; i < parts.Length; i++ ){ arguments += " " + parts[ i ]; } } Process proc = new Process( ); proc.StartInfo.FileName = cmd_name; proc.StartInfo.Arguments = arguments; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardOutput = true; try { if( proc.Start( ) ) { proc.WaitForExit( ); string output = proc.StandardOutput.ReadToEnd().TrimEnd(); string error = proc.StandardError.ReadToEnd().TrimEnd(); if( output.Equals( "" ) || output.Equals( " " ) ) return error; else return output; } } catch( System.ComponentModel.Win32Exception w32e ) { string ret = "Error Thrown: " + w32e.ToString( ); return ret; } return "Broke"; } public bool pipeoutput( string ofile, string cmd ) { StreamWriter file = new StreamWriter( ofile ); try { file.WriteLine( getoutput( cmd ) ); file.Close( ); return true; } catch( System.IO.FileNotFoundException notfound ) { writelog( logfile, notfound.Message.ToString( ) ); return false; } } public string getexitcode( string cmd ) { return runshellcmd( cmd ).ToString(); } public string pwd( ) { string ret = getoutput( "pwd" ); return ret; } public bool killbypid( int pid ) { if( runshellcmd( "kill -9 " + pid ) == 0 ) return true; else return false; } public bool killbyname( string procname ) { //This should actually be "killall -9 + procname", I placed mono in the front because I was killing my own process. Remove to kill other processes by name if( runshellcmd( "killall -9 mono " + procname ) == 0 ) return true; else return false; } public string mygrep( string cmd_to_pipe, string text_to_search ) { string output = ""; //Check if the file exists if( File.Exists( "grep_tmp" ) ) runshellcmd( "rm grep_tmp" ); //Pipe output to a temp file if( pipeoutput( "grep_tmp", cmd_to_pipe) ) { //Set the out variable to the output of the command output = getoutput( "grep -i " + text_to_search + " grep_tmp" ); //Delete the file if( runshellcmd( "rm grep_tmp" ) == 0 ) { //Return the results return output; } } return ""; }
These are some example uses. Stuff I used when debugging.
//Delete the logfile to just make sure I was viewing the most current stuff runshellcmd( "rm " + logfile ); //get workingdir by running the pwd command and returning the output (see pwd() function) string workingdir = pwd( ); //Get processID int procid = System.Diagnostics.Process.GetCurrentProcess().Id; //Get processname string procname = System.Diagnostics.Process.GetCurrentProcess().ProcessName; writelog( logfile, "Working Dir: " + workingdir ); writelog( logfile, "Process ID: " + procid ); writelog( logfile, "Process Name: " + procname ); //We want to search for "process" after we pipe the output from debug.log string tmp = mygrep( "cat debug.log", "process" ); writelog( logfile, "Grep Results:\n" + tmp ); textview1.Buffer.Text = getoutput( "cat debug.log" ); //Kill our process by PID killbypid( procid ); //Kill by our process name killbyname( procname );
[Linux/Mono]C#: Execute Shell Commands (function)
by Chuck Kozler on Feb.14, 2009, under Computers, Linux/Unix, Programming, Ubuntu, Windows
Hi everyone,
This is a short function I wrote to execute a shell command in C#. This needs to be used with Mono on Linux but should run natively on Windows.
protected virtual bool RunCommand( string szCmd, string szArgs, int wait ) { if( szCmd == null ) return false; System.Diagnostics.Process myproc = new System.Diagnostics.Process( ); myproc.EnableRaisingEvents = false; myproc.StartInfo.FileName = szCmd; myproc.StartInfo.Arguments = szArgs; if( myproc.Start( ) ) { //Using WaitForExit( ) allows for the host program //to wait for the command its executing before it continues if( wait == 1 ) myproc.WaitForExit( ); else myproc.Close( ); return true; } else return false; }
If you’re viewing this page then this is pretty self explanatory.
Called as such:
if( RunCommand( "/usr/bin/zenity", "--warning", 0 ) ) Console.WriteLine( "Command ran" );
[Windows] Resolving Standard Internet Connection Problems
by Chuck Kozler on Jan.08, 2009, under Computers, Windows
Problems with wireless and Ethernet/modem connections are usually pretty standard. Below is a checklist of some things to look over before ripping your hair out.
- Wired Internet: Is the little light on the card blinking?
- Look to where the cord plugs in. Check to see if the lights are blinking. If they are blinking then it means the card is probably not defective. From here, just check to make sure it is enabled in Network Connections. If it is enabled and blinking but still not getting an IP address, verify that it is connected correctly and has received an IP from the router.
- Click Start
- Click Run (or just start typing the following command if you’re on Windows Vista)
- Type “cmd”
- A black dialog box with come up, from here type “ipconfig”
- Look to where it says “Local Area Connection #” where # is a number. You may or may not have a number.
- Check to see if it says “IP Address:” along with some other information. If it doesn’t then it will most likely only say “Media Disconnected”. If it is connected with the lights blinking and enabled in Network Connections then you may need to do some further troubleshooting such as Resetting the DNS and DHCP services (see below).
- Look to where the cord plugs in. Check to see if the lights are blinking. If they are blinking then it means the card is probably not defective. From here, just check to make sure it is enabled in Network Connections. If it is enabled and blinking but still not getting an IP address, verify that it is connected correctly and has received an IP from the router.
- Wireless Connections:
- If you keep getting “Limited or no connectivity” messages, see below about resetting some Windows Services.
- Some definitions:
- SSID: This is the name of the router/access-point you are connecting to
- WPA/Network-Key: This is the key that you will have to enter to gain access to the wireless connection. You will need to get this from your router. This is NOT the password that you use to login to your admin control panel for the router, rather, the key you set when you setup the wireless router. This is also NOT the “passphrase” that you set either. The passphrase is used for encryption of your WPA key.
- Ensure you have entered the correct WPA key and that the encryption type you are using matches that of the router. For instance, if your router uses DES encryption, select DES encryption/decryption on your computer in the settings for the connection. On Vista, this is done by selecting the profile in advanced settings and changing the drop down menu to DES or whichever you need to select.
- Restarting Windows Services that handle the above topics:
-
- Definitions:
- DHCP: Dynamic Host Configuration Protocol; This is what automatically assigns you an IP on your local network. This is done by the router.
- DNS: Domain Name System/Service: This resolves domain names to IP’s. Domain names is something such as google.com. When you type google.com in your browser your DNS servers translate google.com into the IP for google and tells your computers IP to connect to that domain’s IP. DNS essentially bridges a small gap between readable human text and computer network text (I.E: Instead of typing googles IP to connect to their website you can just type google.com)
- Services we need to be concerned with:
- Wireless Zero Configuration service
- DNS Service
- DHCP Service
- If you are having problems with your Internet connection then you can go ahead and try restarting each of these three services. To accomplish this, issue these commands
- Click “Start”
- Click “Run” (or if you are on Windows Vista you can just start typing the command for #3)
- Type “services.msc”
- Locate the services named above and right click them and click restart or click stop then right click again and click start
- Definitions:
If all else fails then first restart your router by unplugging the power cord. Once the router comes back online, try reconnecting to it. If you can not reconnect to it then restart the computer.
I would like to hear other peoples suggestions on resolving standard internet connection problems. Please feel free to post them in the comments!
Sphere: Related Content[Windows] Remove AntiVirus 2009
by Chuck Kozler on Jan.08, 2009, under Computers, Security, Windows
Well well, you got the infamous AntiVirus 2009 virus. Ironic how its named that. Or is it? This is what is called malware. You were tricked into downloading it most likely because you got a pop-up window that looked like a legitimate free virus scan, which, then in turn told you that you were infected (go figure). Once you install this, its a huge pain to get rid of.
Removal Instructions:
- Download Malware Bytes: Anti-malware ( http://www.malwarebytes.org/mbam.php ; click green download button, then “download now”, this software is free for what we need)
- Install the software (self explanatory)
- Start the software. If you are prompted to update then select the update. If you are having some problems with the update and are running Windows Vista then you need to make sure you are an admin and have enabled the software in the firewall. If the update hangs after you start the program then simply cancel it and restart it from the dialogs at the top (update tab).
- Start a scan
- Once the scan is complete you will be prompted that you have been infected with some items. Click “Remove Selected”.
If your computer restarts in the middle of a scan or you have some other problems that result in Malware Byte not being able to finish the scan or remove the items then follow these instructions:
- Click Start
- Click Run (or if you have Vista you can just start typing instruction #3)
- Type “msconfig”
- Click the Startup tab
- Remove ALL of the check marks next to everything
- Restart the computer
- Attempt another scan with MalwareBytes Anti-Malware software
If that still does not work. Try these steps:
- Shut down the computer
- When the computer starts back up, instantly start pressing the f8 key
- You will be prompted with Windows’ selection screen. Select “boot with safe mode”.
- From here you will need to select your user at the screen. You will be prompted with a dialog box stating that you are in safe mode. Just click OK.
- Start MalwareBytes Anti-Malware software and proceed with a scan again.
If you have any other problems, post in the comments and I can help you out.
Sphere: Related Content