MCPcopy Create free account
hub / github.com/deepclause/agentvm / setupNetwork

Method setupNetwork

src/index.js:149–170  ·  view source on GitHub ↗

* Sets up the network interface. Called automatically during start() if network is enabled. * Can also be called manually to re-initialize the network. * @returns {Promise<{ip: string, gateway: string}>} Network configuration

()

Source from the content-addressed store, hash-verified

147 * @returns {Promise<{ip: string, gateway: string}>} Network configuration
148 */
149 async setupNetwork() {
150 if (!this.network) {
151 throw new Error('Network is not enabled');
152 }
153
154 // Bring up eth0
155 await this.exec('ip link set eth0 up');
156
157 // Run DHCP client (with timeout to avoid hanging)
158 const dhcpResult = await this.exec('timeout 15 udhcpc -i eth0 -s /sbin/udhcpc.script 2>&1');
159
160 // Extract IP address
161 const ipMatch = dhcpResult.stdout.match(/lease of ([\d.]+) obtained/);
162 const ip = ipMatch ? ipMatch[1] : null;
163
164 // Get gateway from routing table
165 const routeResult = await this.exec('ip route | grep default');
166 const gwMatch = routeResult.stdout.match(/via ([\d.]+)/);
167 const gateway = gwMatch ? gwMatch[1] : null;
168
169 return { ip, gateway };
170 }
171
172 async stop() {
173 this.destroyed = true;

Callers 1

startMethod · 0.95

Calls 1

execMethod · 0.95

Tested by

no test coverage detected