# Namespace: net

## net

Provides basic networking functions, like beef.net.request and beef.net.forgeRequest, used by BeEF command modules and the Requester extension, as well as beef.net.send which is used to return commands to BeEF server-side components.

Also, it contains the core methods used by the XHR-polling mechanism (flush, queue)

Source:
  - net.js, line 7

### Namespaces

connection
cors
dns
local
portscanner
requester
xssrays

### Methods

#### (static) array_has_string_key()

Detects if an array has a string key

Source:
  - net.js, line 507

#### (static) browser_details()

Sends back browser details to framework, calling beef.browser.getDetails()

Source:
  - net.js, line 550

#### (static) chunk(str, amount)

Split the input data into chunk lengths determined by the amount parameter.

##### Parameters:

Name | Type | Description
--- | --- | ---
`str` | String | the input data
`amount` | Integer | chunk length

Source:
  - net.js, line 179

#### (static) clean()

this is a stub, as associative arrays are not parsed by JSON, all key / value pairs should use new Object() or {} http://andrewdupont.net/2006/05/18/javascript-associative-arrays-considered-harmful/

Source:
  - net.js, line 496

#### (static) command()

Command object. This represents the data to be sent back to BeEF, using the beef.net.send() method.

Source:
  - net.js, line 35

#### (static) flush()

Flush all currently queued command results to the framework, chopping the data in chunks ('chunk' method) which will be re-assembled server-side by the network stack. NOTE: currently 'flush' is used only with the default XHR-polling mechanism. If WebSockets are used, the data is sent back to BeEF straight away.

Source:
  - net.js, line 147

#### (static) forge_request()

Similar to beef.net.request, except from a few things that are needed when dealing with forged requests:

- requestid: needed on the callback
- allowCrossDomain: set cross-domain requests as allowed or blocked

forge_request is used mainly by the Requester and Tunneling Proxy Extensions. Example usage: beef.net.forge_request("http", "POST", "172.20.40.50", 8080, "/lulz", true, null, { foo: "bar" }, 5, 'html', false, null, function(response) { alert(response.response_body)})

Source:
  - net.js, line 321

#### (static) is_valid_ip()

Checks if the specified IP address is valid

Source:
  - net.js, line 530

#### (static) is_valid_ip_range()

Checks if the specified IP address range is valid

Source:
  - net.js, line 540

#### (static) is_valid_port()

Checks if the specified port is valid

Source:
  - net.js, line 521

#### (static) packet()

Packet object. A single chunk of data. X packets -> 1 stream

Source:
  - net.js, line 46

#### (static) push(stream)

Push the input stream back to the BeEF server-side components. It uses beef.net.request to send back the data.

##### Parameters:

Name | Type | Description
--- | --- | ---
`stream` | Object | the stream object to be sent back.

Source:
  - net.js, line 189

#### (static) queue(handler, cid, results, status, callback)

Queues the specified command results.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | String | the server-side handler that will be called
`cid` | Integer | command id
`results` | String | the data to send
`status` | Integer | the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success')
`callback` | function | the function to call after execution

Source:
  - net.js, line 91

#### (static) request(scheme, method, domain, port, path, anchor, data, timeout, dataType, callback) → {Object}

Performs http requests

##### Parameters:

Name | Type | Description
--- | --- | ---
`scheme` | String | HTTP or HTTPS
`method` | String | GET or POST
`domain` | String | bindshell.net, 192.168.3.4, etc
`port` | Int | 80, 5900, etc
`path` | String | /path/to/resource
`anchor` | String | this is the value that comes after the # in the URL
`data` | String | This will be used as the query string for a GET or post data for a POST
`timeout` | Int | timeout the request after N seconds
`dataType` | String | specify the data return type expected (ie text/html/script)
`callback` | function | call the callback function at the completion of the method

Source:
  - net.js, line 219

##### Returns:

this object contains the response details

Type
  Object

#### (static) response()

Response Object - used in the beef.net.request callback NOTE: as we are using async mode, the response object will be empty if returned. Using sync mode, request obj fields will be populated.

Source:
  - net.js, line 72

#### (static) send(handler, cid, results, exec_status, callback) → {Integer}

Queues the current command results and flushes the queue straight away. NOTE: Always send Browser Fingerprinting results (beef.net.browser_details(); -> /init handler) using normal XHR-polling, even if WebSockets are enabled.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | String | the server-side handler that will be called
`cid` | Integer | command id
`results` | String | the data to send
`exec_status` | Integer | the result of the command execution (-1, 0 or 1 for 'error', 'unknown' or 'success')
`callback` | function | the function to call after execution

Source:
  - net.js, line 115

##### Returns:

the command module execution status (defaults to 0 - 'unknown' if status is null)

Type
  Integer

#### (static) stream()

Stream object. Contains X packets, which are command result chunks.

Source:
  - net.js, line 54