Skip to content

Commit cfba194

Browse files
committed
Add command implementations for network and system utilities
- Implemented NetstatCommand to display active TCP connections and listening ports. - Added NslookupCommand for DNS queries to obtain domain name or IP address mapping. - Created PathCommand to display or set the command path. - Introduced RemCommand for adding comments in batch files or scripts. - Developed ReplaceCommand for replacing files in a directory. - Implemented RobocopyCommand for advanced file copying. - Added RouteCommand to display and modify entries in the local IP routing table. - Created SfcCommand for system file checking and verification. - Implemented ShutdownCommand to shut down or restart the computer. - Added SortCommand to sort the contents of a text file. - Developed StartCommand to start a separate window for running programs. - Implemented TaskkillCommand to terminate processes by ID or image name. - Added TimeoutCommand to delay execution for a specified time period. - Created TracertCommand to trace the route packets take to a network host. - Implemented VerifyCommand to enable or disable file verification. - Added VolCommand to display the volume label and serial number of a disk. - Created WmicCommand for executing Windows Management Instrumentation queries. - Implemented XcopyCommand for copying files and directory trees.
1 parent 0f5fb4f commit cfba194

40 files changed

+3027
-49
lines changed

CheckList.md

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
- [x] systeminfo
1111
- [x] hostname
1212
- [x] ver
13-
- [ ] vol
14-
- [ ] set
13+
- [x] vol
14+
- [x] set
1515
- [ ] setx
16-
- [ ] wmic
17-
- [ ] driverquery
18-
- [ ] tasklist
19-
- [ ] taskkill
20-
- [ ] sfc
21-
- [ ] chkdsk
22-
- [ ] label
23-
- [ ] fsutil
24-
- [ ] assoc
25-
- [ ] ftype
16+
- [x] wmic
17+
- [x] driverquery
18+
- [x] tasklist
19+
- [x] taskkill
20+
- [x] sfc
21+
- [x] chkdsk
22+
- [x] label
23+
- [x] fsutil
24+
- [x] assoc
25+
- [x] ftype
2626

2727
---
2828

@@ -33,46 +33,46 @@
3333
- [x] rd / rmdir
3434
- [x] del / erase
3535
- [x] copy
36-
- [ ] xcopy
37-
- [ ] robocopy
36+
- [x] xcopy
37+
- [x] robocopy
3838
- [x] move
39-
- [ ] rename / ren
40-
- [ ] attrib
39+
- [x] rename / ren
40+
- [x] attrib
4141
- [x] tree
4242
- [x] type
43-
- [ ] more
44-
- [ ] find
45-
- [ ] findstr
46-
- [ ] sort
47-
- [ ] fc
48-
- [ ] forfiles
49-
- [ ] compact
50-
- [ ] replace
43+
- [x] more
44+
- [x] find
45+
- [x] findstr
46+
- [x] sort
47+
- [x] fc
48+
- [x] forfiles
49+
- [x] compact
50+
- [x] replace
5151

5252
---
5353

5454
## 🌐 Network & Internet Commands
5555
- [x] ping
56-
- [ ] ipconfig
57-
- [ ] getmac
58-
- [ ] nslookup
59-
- [ ] netstat
60-
- [ ] tracert
56+
- [x] ipconfig
57+
- [x] getmac
58+
- [x] nslookup
59+
- [x] netstat
60+
- [x] tracert
6161
- [ ] pathping
62-
- [ ] arp
63-
- [ ] route
64-
- [ ] netsh
62+
- [x] arp
63+
- [x] route
64+
- [x] netsh
6565
- [ ] ftp
6666
- [ ] tftp
67-
- [ ] telnet
67+
- [x] telnet
6868
- [ ] nbtstat
69-
- [ ] net
70-
- [ ] net user
71-
- [ ] net use
72-
- [ ] net share
73-
- [ ] net start
74-
- [ ] net stop
75-
- [ ] net session
69+
- [x] net
70+
- [x] net user
71+
- [x] net use
72+
- [x] net share
73+
- [x] net start
74+
- [x] net stop
75+
- [x] net session
7676
- [ ] curl
7777
- [ ] powershell
7878

@@ -115,12 +115,12 @@
115115
- [x] color
116116
- [x] time
117117
- [x] date
118-
- [ ] shutdown
119-
- [ ] choice
120-
- [ ] timeout
118+
- [x] shutdown
119+
- [x] choice
120+
- [x] timeout
121121
- [ ] call
122-
- [ ] start
123-
- [ ] taskkill
122+
- [x] start
123+
- [x] taskkill
124124
- [ ] schtasks
125125
- [ ] for
126126
- [ ] if
@@ -158,11 +158,11 @@
158158
- [ ] mode
159159
- [ ] print
160160
- [ ] subst
161-
- [ ] clip
162-
- [ ] msg
161+
- [x] clip
162+
- [x] msg
163163
- [x] ver
164-
- [ ] verify
165-
- [ ] vol
164+
- [x] verify
165+
- [x] vol
166166

167167
---
168168

src/main/java/com/mycmd/App.java

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,75 +76,155 @@ private static String resolveAliases(String input, ShellContext context) {
7676
private static final class CommandNames {
7777
private CommandNames() {}
7878
private static final String ALIAS = "alias";
79+
private static final String ARP = "arp";
80+
private static final String ASSOC = "assoc";
81+
private static final String ATTRIB = "attrib";
7982
private static final String CD = "cd";
83+
private static final String CHKDSK = "chkdsk";
84+
private static final String CHOICE = "choice";
8085
private static final String CLEARHISTORY = "clearhistory";
86+
private static final String CLIP = "clip";
8187
private static final String CLS = "cls";
8288
private static final String COLOR = "color";
89+
private static final String COMPACT = "compact";
8390
private static final String COPY = "copy";
8491
private static final String DATE = "date";
8592
private static final String DEL = "del";
8693
private static final String DIR = "dir";
94+
private static final String DRIVERQUERY = "driverquery";
8795
private static final String ECHO = "echo";
8896
private static final String EXIT = "exit";
97+
private static final String FC = "fc";
98+
private static final String FIND = "find";
99+
private static final String FINDSTR = "findstr";
100+
private static final String FORFILES = "forfiles";
101+
private static final String FSUTIL = "fsutil";
102+
private static final String FTYPE = "ftype";
103+
private static final String GETMAC = "getmac";
89104
private static final String HELP = "help";
90105
private static final String HISTORY = "history";
91106
private static final String HOSTNAME = "hostname";
92107
private static final String IPCONFIG = "ipconfig";
108+
private static final String LABEL = "label";
109+
private static final String LS = "ls";
93110
private static final String MKDIR = "mkdir";
111+
private static final String MORE = "more";
112+
private static final String MOVE = "move";
113+
private static final String MSG = "msg";
114+
private static final String NET = "net";
115+
private static final String NETSH = "netsh";
116+
private static final String NETSTAT = "netstat";
117+
private static final String NSLOOKUP = "nslookup";
118+
private static final String PATH = "path";
94119
private static final String PAUSE = "pause";
95120
private static final String PING = "ping";
96121
private static final String PWD = "pwd";
122+
private static final String REM = "rem";
97123
private static final String RENAME = "rename";
124+
private static final String REPLACE = "replace";
98125
private static final String RMDIR = "rmdir";
126+
private static final String ROBOCOPY = "robocopy";
127+
private static final String ROUTE = "route";
99128
private static final String SET = "set";
129+
private static final String SFC = "sfc";
130+
private static final String SHUTDOWN = "shutdown";
131+
private static final String SORT = "sort";
132+
private static final String START = "start";
100133
private static final String SYSTEMINFO = "systeminfo";
134+
private static final String TASKKILL = "taskkill";
101135
private static final String TASKLIST = "tasklist";
102136
private static final String TELNET = "telnet";
103137
private static final String TIME = "time";
138+
private static final String TIMEOUT = "timeout";
104139
private static final String TITLE = "title";
105140
private static final String TOUCH = "touch";
141+
private static final String TRACERT = "tracert";
106142
private static final String TREE = "tree";
107143
private static final String TYPE = "type";
108144
private static final String UNALIAS = "unalias";
109145
private static final String UPTIME = "uptime";
110146
private static final String VER = "ver";
147+
private static final String VERIFY = "verify";
148+
private static final String VOL = "vol";
111149
private static final String WHOAMI = "whoami";
150+
private static final String WMIC = "wmic";
151+
private static final String XCOPY = "xcopy";
112152
}
113153

114154
private static void registerCommands(Map<String, Command> commands) {
115155
commands.put(CommandNames.ALIAS, new AliasCommand());
156+
commands.put(CommandNames.ARP, new ArpCommand());
157+
commands.put(CommandNames.ASSOC, new AssocCommand());
158+
commands.put(CommandNames.ATTRIB, new AttribCommand());
116159
commands.put(CommandNames.CD, new CdCommand());
160+
commands.put(CommandNames.CHKDSK, new ChkdskCommand());
161+
commands.put(CommandNames.CHOICE, new ChoiceCommand());
117162
commands.put(CommandNames.CLEARHISTORY, new ClearHistoryCommand());
163+
commands.put(CommandNames.CLIP, new ClipCommand());
118164
commands.put(CommandNames.CLS, new ClsCommand());
119165
commands.put(CommandNames.COLOR, new ColorCommand());
166+
commands.put(CommandNames.COMPACT, new CompactCommand());
120167
commands.put(CommandNames.COPY, new CopyCommand());
121168
commands.put(CommandNames.DATE, new DateCommand());
122169
commands.put(CommandNames.DEL, new DelCommand());
123170
commands.put(CommandNames.DIR, new DirCommand());
171+
commands.put(CommandNames.DRIVERQUERY, new DriverqueryCommand());
124172
commands.put(CommandNames.ECHO, new EchoCommand());
125173
commands.put(CommandNames.EXIT, new ExitCommand());
174+
commands.put(CommandNames.FC, new FcCommand());
175+
commands.put(CommandNames.FIND, new FindCommand());
176+
commands.put(CommandNames.FINDSTR, new FindstrCommand());
177+
commands.put(CommandNames.FORFILES, new ForfilesCommand());
178+
commands.put(CommandNames.FSUTIL, new FsutilCommand());
179+
commands.put(CommandNames.FTYPE, new FtypeCommand());
180+
commands.put(CommandNames.GETMAC, new GetmacCommand());
126181
commands.put(CommandNames.HELP, new HelpCommand(commands));
127182
commands.put(CommandNames.HISTORY, new HistoryCommand());
128183
commands.put(CommandNames.HOSTNAME, new HostnameCommand());
129184
commands.put(CommandNames.IPCONFIG, new IpConfig());
185+
commands.put(CommandNames.LABEL, new LabelCommand());
186+
commands.put(CommandNames.LS, new LsCommand());
130187
commands.put(CommandNames.MKDIR, new MkdirCommand());
188+
commands.put(CommandNames.MORE, new MoreCommand());
189+
commands.put(CommandNames.MOVE, new MoveCommand());
190+
commands.put(CommandNames.MSG, new MsgCommand());
191+
commands.put(CommandNames.NET, new NetCommand());
192+
commands.put(CommandNames.NETSH, new NetshCommand());
193+
commands.put(CommandNames.NETSTAT, new NetstatCommand());
194+
commands.put(CommandNames.NSLOOKUP, new NslookupCommand());
195+
commands.put(CommandNames.PATH, new PathCommand());
131196
commands.put(CommandNames.PAUSE, new PauseCommand());
132197
commands.put(CommandNames.PING, new PingCommand());
133198
commands.put(CommandNames.PWD, new PwdCommand());
199+
commands.put(CommandNames.REM, new RemCommand());
134200
commands.put(CommandNames.RENAME, new RenameCommand());
201+
commands.put(CommandNames.REPLACE, new ReplaceCommand());
135202
commands.put(CommandNames.RMDIR, new RmdirCommand());
203+
commands.put(CommandNames.ROBOCOPY, new RobocopyCommand());
204+
commands.put(CommandNames.ROUTE, new RouteCommand());
136205
commands.put(CommandNames.SET, new SetCommand());
206+
commands.put(CommandNames.SFC, new SfcCommand());
207+
commands.put(CommandNames.SHUTDOWN, new ShutdownCommand());
208+
commands.put(CommandNames.SORT, new SortCommand());
209+
commands.put(CommandNames.START, new StartCommand());
137210
commands.put(CommandNames.SYSTEMINFO, new SysteminfoCommand());
211+
commands.put(CommandNames.TASKKILL, new TaskkillCommand());
138212
commands.put(CommandNames.TASKLIST, new TasklistCommand());
139213
commands.put(CommandNames.TELNET, new TelnetCommand());
140214
commands.put(CommandNames.TIME, new TimeCommand());
215+
commands.put(CommandNames.TIMEOUT, new TimeoutCommand());
141216
commands.put(CommandNames.TITLE, new TitleCommand());
142217
commands.put(CommandNames.TOUCH, new TouchCommand());
218+
commands.put(CommandNames.TRACERT, new TracertCommand());
143219
commands.put(CommandNames.TREE, new TreeCommand());
144220
commands.put(CommandNames.TYPE, new TypeCommand());
145221
commands.put(CommandNames.UNALIAS, new UnaliasCommand());
146222
commands.put(CommandNames.UPTIME, new UptimeCommand());
147223
commands.put(CommandNames.VER, new VersionCommand());
224+
commands.put(CommandNames.VERIFY, new VerifyCommand());
225+
commands.put(CommandNames.VOL, new VolCommand());
148226
commands.put(CommandNames.WHOAMI, new WhoamiCommand());
227+
commands.put(CommandNames.WMIC, new WmicCommand());
228+
commands.put(CommandNames.XCOPY, new XcopyCommand());
149229
}
150230
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.mycmd.commands;
2+
3+
import com.mycmd.Command;
4+
import com.mycmd.ShellContext;
5+
6+
import java.io.BufferedReader;
7+
import java.io.IOException;
8+
import java.io.InputStreamReader;
9+
10+
/**
11+
* Displays and modifies the IP-to-Physical address translation tables (ARP cache).
12+
*
13+
* Usage:
14+
* - arp -a : Display ARP cache
15+
*/
16+
public class ArpCommand implements Command {
17+
18+
@Override
19+
public void execute(String[] args, ShellContext context) throws IOException {
20+
try {
21+
StringBuilder cmdBuilder = new StringBuilder("arp");
22+
for (String arg : args) {
23+
cmdBuilder.append(" ").append(arg);
24+
}
25+
26+
// Default to -a if no args provided
27+
if (args.length == 0) {
28+
cmdBuilder.append(" -a");
29+
}
30+
31+
ProcessBuilder pb = new ProcessBuilder();
32+
String os = System.getProperty("os.name").toLowerCase();
33+
34+
if (os.contains("win")) {
35+
pb.command("cmd.exe", "/c", cmdBuilder.toString());
36+
} else {
37+
pb.command("sh", "-c", cmdBuilder.toString());
38+
}
39+
40+
Process process = pb.start();
41+
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
42+
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
43+
44+
String line;
45+
while ((line = reader.readLine()) != null) {
46+
System.out.println(line);
47+
}
48+
49+
while ((line = errorReader.readLine()) != null) {
50+
System.err.println(line);
51+
}
52+
53+
process.waitFor();
54+
55+
} catch (Exception e) {
56+
System.out.println("Error executing arp: " + e.getMessage());
57+
}
58+
}
59+
60+
@Override
61+
public String description() {
62+
return "Displays and modifies the IP-to-Physical address translation tables.";
63+
}
64+
65+
@Override
66+
public String usage() {
67+
return "arp [-a] [-d ip_addr] [-s ip_addr eth_addr]";
68+
}
69+
}

0 commit comments

Comments
 (0)