Sunteți pe pagina 1din 3

Data Communication & Networking I week 2 Practical Lecture

Process & Runtime


It uses to execute a “cmd” commands on java applications that provide an
environment using process and runtime classes.
Runtime class  allows the application to interface with the environment in which
the application is running.
Process class  create a native process and return an instance of a subclass
of Process that can be used to control the process and obtain information about it.
The class Process provides methods for performing input from the process,
performing output to the process, waiting for the process to complete, checking the
exit status of the process, and destroying (killing) the process.
BufferedReader class  Reads text from a character-input stream, buffering
characters so as to provide for the efficient reading of characters, arrays, and lines
(Temporary storage).
inputStreamReader class  a bridge from byte streams to character streams. It
reads bytes and decodes them into characters using a specified charset.
The used functions when you create object are as follow:
1. getRuntime()  Returns the runtime object associated with the current Java
application.
2. getInputStream()  Returns the input stream connected to the normal output
of the subprocess.
3. getOutputStream()  Returns the output stream connected to the normal
input of the subprocess.
4. exec (String command)  Executes the specified string command in a
separate process. Returns A new Process object for managing the subprocess.
5. readLine()  Reads a line of text. A line is considered to be terminated by
any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed
immediately by a linefeed.

1|P ag e By: Ghasaq Bahaa


Data Communication & Networking I week 2 Practical Lecture

Code:

Notes:
a. “while” loop has been used in order to print multiple lines of the command
output until there is null line (empty).
b. The output of the “Process” is in byte format and when “BufferedReader”
reads the output, it must be in string or character format. Then,
“InputStreamReader” class converts it.
c. “getInputStream” function is getting the data in byte format.
d. The most common “cmd” commands that you can use on windows are as
follow:
1. ping + ip or domain
Test the ability of one network host to communicate with another.
2. tracert + ip or domain
Examine the path to a remote host. It works similar to ping but the
difference is sending a series of ICMP echo request and the TTL increased
by 1 each time. Allow to display the routes through which packets are
passing. In each hop it sends 3 packets of data and measures the time.
3. ipconfig or ipconfig /all
Display basic IP address configuration information for the device such as
IP, subnet mask , default gateway, and etc. you will have to use /all if you
want to see DNS server information that the windows is configured to use.

2|P ag e By: Ghasaq Bahaa


Data Communication & Networking I week 2 Practical Lecture

It uses as well to troubleshooting problems that are related to DNS and


DHCP.
4. hostname
Return the name of the computer (machine).
5. netstat –e
Display network summary information for the device when you have
problem with the network communication.
6. arp –a
Map the IP addresses to MAC addresses.
7. nslookup
Diagnosing DNS problems.
8. pathping + ip or domain
Combines the best aspects of “tracert” and “ping”. It takes 5 minutes
9. getmac
Return the mac address (es)

References:
https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html
https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html
https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html
https://docs.oracle.com/javase/7/docs/api/java/io/InputStreamReader.html
http://support.seagate.com/rightnow/Flash/central_axis/IPCommands.pdf
https://help.fasthosts.co.uk/app/answers/detail/a_id/1550/kw/traceroute

3|P ag e By: Ghasaq Bahaa

S-ar putea să vă placă și