Assignment No. 3(B-10) Title Linux networking commands emulation Roll No. Class T.E. Date Subject Programming Lab IV Signature Department of Computer Engineering, SKNCOE, Pune Assignment No:3(B-10) Title: Linux networking commands emulation Problem Statement: Study and perform Linux networking commands emulation using Python or C++. Prerequisites: Basics of networking Linux networking commands. Objectives: 1] To study the linux networking commands. 2] To study concept of emulator. Tools: Operating System: Fedora19. Programming Language: Python. Theory: Emulator: In computing, an emulator is hardware or software that enables one computer system (called the host) to behave like a computer system (called the guest). An emulator typically enables the host system to run software or use peripheral devices designed for the guest system. Emulation: Emulation is a strategy in digital preservation to combat obsolescence. Emulation focuses on recreating an original computer environment, which can be time-consuming and difficult to achieve, but valuable because of its ability to maintain a closer connection to the authenticity of the digital object. Emulation addresses the original hardware and software environment of the digital object, Department of Computer Engineering, SKNCOE, Pune and recreates it on a current machine. The emulator allows the user to have access to any kind of application or operating system on a current platform, while the software runs as it did in its original environment. Jeffery Rothenberg, an early proponent of emulation as a digital preservation strategy states, "the ideal approach would provide a single extensible, long-term solution that can be designed once and for all and applied uniformly, automatically, and in synchrony (for example, at every refresh cycle) to all types of documents and media". He further states that this should not only apply to out of date systems, but also be upwardly mobile to future unknown systems. Practically speaking, when a certain application is released in a new version, rather than address compatibility issues and migration for every digital object created in the previous version of that application, one could create an emulator for the application, allowing access to all of said digital objects. Most emulators just emulate a hardware architecture—if operating system firmware or software is required for the desired software, it must be provided as well (and may itself be emulated). Both the OS and the software will then be interpreted by the emulator, rather than being run by native hardware. Apart from this interpreter for the emulated binary machine's language, some other hardware (such as input or output devices) must be provided in virtual form as well; for example, if writing to a specific memory location should influence what is displayed on the screen, then this would need to be emulated. Benefits: Potentially better graphics quality than original hardware. Potentially additional features original hardware didn't have. Save states Emulators allow users to play games for discontinued consoles. Emulators maintain the original look, feel, and behavior of the digital object, which is just as important as the digital data itself. Despite the original cost of developing an emulator, it may prove to be the more cost efficient solution over time. Reduces labor hours, because rather than continuing an ongoing task of continual data migration for every digital object, once the library of past and present operating systems and application software is established in an emulator, these same technologies are used for every document using those platforms. Many emulators have already been developed and released under GNU General Public License through the open source environment, allowing for wide scale collaboration. Emulators allow software exclusive to one system to be used on another. For example, a Department of Computer Engineering, SKNCOE, Pune PlayStation 2 exclusive video game could be played on a PC using an emulator. This is especially useful when the original system is difficult to obtain, or incompatible with modern equipment (e.g. old video game consoles which connect via analog outputs may be unable to connect to modern TVs which may only have digital inputs). Functions: 1] Cmd: The cmd module contains one public class, Cmd, designed to be used as a base class for command processors such as interactive shells and other command interpreters. By default it uses readline for interactive prompt handling, command line editing, and command completion. 2] Popen(): The method popen() opens a pipe to or from command.The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'.The bufsize argument has the same meaning as in open() function. Syntax: Following is the syntax for popen() method: os.popen(command[, mode[, bufsize]]) Parameters: 1. Command -- This is command used. 2. mode -- This is the Mode can be 'r'(default) or 'w'. 3. bufsize -- If the buffering value is set to 0, no buffering will take place. If the buffering value is 1, line buffering will be performed while accessing a file. If you specify the buffering value as an integer greater than 1, then buffering action will be performed with the indicated buffer size. If negative, the buffer size is the system default(default behavior). 3] Replace: The method replace() returns a copy of the string in which the occurrences of old have been replaced with new, optionally restricting the number of replacements to max. Syntax: Following is the syntax for replace() method: str.replace(old, new[, max]) Parameters: Department of Computer Engineering, SKNCOE, Pune old -- This is old substring to be replaced. new -- This is new substring, which would replace old substring. max -- If this optional argument max is given, only the first count occurrences are replaced. 4] Read: The method read() reads at most size bytes from the file. If the read hits EOF before obtaining size bytes, then it reads only available bytes. Syntax: Following is the syntax for read() method: fileObject.read( size ); Parameters: size -- This is the number of bytes to be read from the file. Linux Networking Commands: 1] netstat: Displays contents of /proc/net files. It works with the Linux Network Subsystem, it will tell you what the status of ports are ie. Open, closed, waiting, masquerade connections. It will also display various other things. It has many different options. Syntax: netstat [address_family_options] [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [-numeric|-n] [--numeric-hosts][--numeric-ports][--numeric-ports] [--symbolic|-N] [-extend|-e[--extend|-e]] [--timers|-o] [--program|-p] [--verbose|-v] [--continuous|-c] [delay] 2] dig: dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig. Syntax: Department of Computer Engineering, SKNCOE, Pune dig [@server] [-b address] [-c class] [-f filename] [-k filename] [-m] [-p port#] [-q name] [-t type] [-x addr] [-y [hmac:]name:key] [-4] [-6] [name] [type] [class] [queryopt...] dig [-h] dig [global-queryopt...] [query...] 3] ping: The ping command (named after the sound of an active sonar system) sends echo requests to the host you specify on the command line, and lists the responses received their round trip time. You simply use ping as: ping ip_or_host_name 4] hostname: Tells the user the host name of the computer they are logged into. Note: may be called host. 5] traceroute: traceroute will show the route of a packet. It attempts to list the series of hosts through which your packets travel on their way to a given destination. Also have a look at xtraceroute (one of severalgraphical equivalents of this program). Command syntax: traceroute machine_name_or_ip 6] host: Performs a simple lookup of an internet address (using the Domain Name System, DNS). Simply type: host ip_address or host domain_name 7] whois: (now BW whois) is used to look up the contact information from the “whois” databases, the servers are only likely to hold major sites. Note that contact information is likely to be hidden or restricted as it is often abused by crackers and others looking for a way to cause malicious damage to organisation's. Department of Computer Engineering, SKNCOE, Pune Conclusion: In this assignment, we studied the basic linux networking commands emulation using python. Department of Computer Engineering, SKNCOE, Pune