Friday 26 September 2014

Python Program to check if system is Booted with BOIS or UEFI


*********** Execute This code on Windows system **********



#bios.py

def check():
    infile=open("c:\windows\panther\setupact.log","r+");
    available=False
    for line in infile:
        if"Detected boot environment:BIOS" in line:
in line
        available=True
        break
    return available

available=check()
if available:
    print(".......System Boot type : Legacy Boot ROM-BIOS......!!!")
else:
    print(".......System is Booted with UEFI.....")





Java Program to verify Mobile Device OS Version and name

Execute This program on Eclipse for Android

Create .apk file using emulator and execute .apk  file on Android OS



import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity
{
  @override
public void onCreate(Bundle savedInstanceState)
{
 super.onCreate(savedInstanceState);
TextView text=new TextView(this);

text.setText("\n System Information "+"\n Operating System Name :"+System.getProperty("os.name")+"\n Version "+
System.getProperty("os.version")+"\n Architecture :"+System.getProperty("os.arch")+"\n Manufacturer :"+
android.os.Build.MANUFACTURER+"\n Display type :"+android.os.Build.DISPLAY+"\n Model :"+
android.os.Build.MODEL+"\n Product:"+android.os.Build.PRODUCT+"\n User:"+android.os.Build.USER);
}
}

Friday 19 September 2014

Write a program in C++ to make USB Device Bootable by installing required system files

To Create Bootable USB , we need to copy following files in USB.
Write a program in C++ top copy a file from Your system to USB drive.

Files Required to create a Bootable Drive :
1. CONFIG.SYS
2. SYS.COM
3. IO.SYS
4. MSDOS.SYS
5. COMMAND.SYS


On copying these files just restart your system.

We can copy more files from MSDOS system files to add more functionality.
Following is list of various MSDOS System Files that can be used to add more
functionality.

List of MS-DOS system files
MS-DOS / PC DOS and some related disk operating systems use the files mentioned here.

System Files:
• IO.SYS (or IBMBIO.COM): This contains the system initialization code and
builtin device drivers.
• MSDOS.SYS (or IBMDOS.COM): This contains the DOS kernel.

Command line interpreter (Shell):
• COMMAND.COM: This is the command interpreter.

User configuration files:
• AUTOEXEC.BAT: This is run by the default shell (usually COMMAND.COM) to
execute commands at startup.
• CONFIG.SYS: This contains statements to configure DOS and load device
drivers.

Standard DOS utility programs:
• APPEND: Set a search path for data files.
• ATTRIB: Set or display file attributes.
• BACKUP / RESTORE: simple backup and restore utilities.
• CHKDSK: Check disk for file system integrity.
• COMP / FC: File compare utilities.
• DEBUG: Simple command line debugger.
• DELTREE: Delete a directory tree.
• DISKCOMP: Compare floppy disks.
• DISKCOPY: Copy floppy disks.
• DOSKEY: Command line editor.
• EDIT / EDLIN: Very basic text editor(s); EDLIN is in earlier versions.
• FDISK: Partitions fixed disks.
• FIND: Find text in files.
• FORMAT: Formats disks.
• JOIN: Joins a drive letter to a subdirectory.
• LABEL: Set or remove a disk volume label.
• MEM: Display memory usage.
• MODE: Set modes for system devices.
• MORE: Display output one screen at a time.
• MOVE: Move files from one directory to another.
• PRINT: Print spooler.
• REPLACE: Replace files.
• SHARE: File sharing and locking support.
• SORT: Sorts input.
• SUBST: Substitutes a drive letter for a subdirectory.
• SYS: Transfers the system files to another drive to make it bootable.
• TREE: Display a directory tree.
• XCOPY: Extended file copy.
Standard DOS device drivers:
• ANSI.SYS: ANSI console driver.
• EMM386.EXE: Expanded memory manager.
• HIMEM.SYS: Extended memory manager.
• RAMDRIVE.SYS / VDISK.SYS: RAM disk; VDISK.SYS is in older versions of PC
DOS.

Download required files to a directory (eg: Documents)

Sample C++ code :

Add lines of code for remaining files.

#include<stdlib.h>
#include<iostream>
#include<fstream>
using namespace std;

int main()
{
 ofstream fpon;
 ifstream fpin;
 string line;

fpin.open("/home/Downloads/CONFIG.SYS");
fpon.open("/dev/sdb1/CONFIG.SYS");

 if(fpin.is_open())
  {
   while(getline(fpin,line))
    {
          fpon<<line;
         } //while ends
    } //if ends

 fpon.close();
 fpin.close();

    //in same way write code for reamining files , repeat above code and change
    //name of file only.

cout<<"All files copied"<<endl<<"Now device is bootable";
return 0;

}//main ends

How to Format USB Drive in the Terminal

I see formatting USB drives from the terminal very handy. Today I am going to show you how to format USB drives using the terminal. Things needed for this tutorial to be useful is just a USB drive, the capacity doesn’t matter.
Let us get started!
1. Insert your USB drive into your system.
2. Open the terminal. (CTRL + ALT + T)
3. Look for the USB drive you want to format, by running:
$ df
The command above will display the directory path of your various drives. Take note of the drive you wish to format.
df-command-unixmenIn this tutorial, the name of the drive am going to format is Seth and its path under the filesystem is /dev/sdc1.
3. Unmount drive using the syntax below:
$ sudo umount /dev/sdc1
umount4. Now run this command to format drive to fat32:
$ sudo mkfs.vfat -n 'Ubuntu' -I /dev/sdc1
mkfs.vfat-unixmen
Understanding the above command
mkfs
mkfs is used to build a Linux filesystem on a device, usually a hard disk partition. The device argument is either the device name (e.g. /dev/hda1, /dev/sdb2), or a regular file that shall contain the filesystem. The size argument is the number of blocks to be used for the filesystem.
vfat
Formats the drive to FAT32, other formats available are mkfs.bfs, mkfs.ext2, mkfs.ext3, mkfs.ext4, mkfs.minix, mkfs.msdos, mkfs.vfat, mkfs.xfs, mkfs.xiafs etc.
-n
Volume-name sets the volume name (label) of the file system. The volume name can be up to 11 characters long. The default is no label. In this tutorial my volume-name is Ubuntu.
-I
It is typical for fixed disk devices to be partitioned so by default, you are not permitted to create a filesystem across the entire device.
format-completeRunning $ df after formatting displays this.
df-after-format-unixmenYou are done and your pen drive has successfully been formatted.

Tuesday 16 September 2014

C++ Program to create RAMDRIVE or RAMDISk and run Calculator Program in it.

1. Create Input File in /tmp/ramdisk for input
          name it as input.txt

2. Write a Program for calculator in C

code is as follow

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int a,b,res;
 FILE *fp;
 fp=fopen("/tmp/ramdisk/input.txt","r");
 fscanf(fp,"%d",&a);
 fscanf(fp,"%d",&b);
 fclose(fp);
  fp=fopen("/tmp/ramdisk/output.txt","w");
 fprintf(fp,"\n Addition is :%d ",(a+b));
return 0;
}


save it as calci.c and compile using command
          gcc calci.c -o  calculator


3. Write program for RAMDISK in C language
     
    #include<stdio.h>
#include<stdlib.h>
int main()
{
  printf("\n RAMDISK creation for 512M size");
  system("rmdir /tmp/ramdisk");
  system("mkdir /tmp/ramdisk");
  system("chmod 777 /tmp/ramdisk");
  system("mount -t tmpfs -o size=512M tmpfs /tmp/ramdisk/");
  printf("\n RAMDISK created");
  system("df -h|grep ram");
  system("cp input.txt /tmp/ramdisk");
  system("cp calculator /tmp/ramdisk");
  return 0;
}

save it as ramdisk.c and compile as

gcc ramdisk.c -o ramdisk

execute output of above command as
        ramdisk <Enter>

4. Calculator code can be executed using command
        /tmp/ramdisk/calculator

5. Output is saved in output.txt file. Check it from /tmp/ramdisk/output.txt





Friday 5 September 2014

Python program for socket programming to connect two or more PC to share a text file

#1.Server side code

#!/usr/bin/python

import socket
import os

s=socket.socket()      #socket type object created
host=192.168.1.214    #server address
port=21110        #port reserverd for connection
s.bind((host,port))

s.listen(10)

while True:
    c, addrs= s.accept();
    print'Connection created with machine',addrs
    name=c.recv(100)    #receive file name to be read/shared
    print name,'File requested by User'
    file=open(name,"r")    #open file in read mode
   
while True:
    cha=file.read(65500)    #read data from file upto 65500 bytes
    if not cha:
    break            #reached end of file
   c.sendall(cha)        #send file content to requester
c.close()            #close connection


*********************** ******************************

#2.Client side code

#!usr/bin/python

import socket

s=socket.socket()        #socket object created
host=192.168.1.214
port=21110

s.connect((host,port))        #connect with sserver on port
print'Enter file name to be read'
name=raw_input()        #accept input from user
s.send(name)            #send name of file to server
print s.recv(65500)        #receive data from server and print on screen
s.close()            #close connection with server





#change host number as per your system configuration for ip address
#host should be server machine address