Closed brichard1638 closed 3 months ago
Implemented
could not find a suitable revision across all platforms for this function. But I was blind to the fact that the only issue with this function is the example 1 with the ipconfig. we just have to remove that and it will be fine.
I have recently been pursuing the possibility of developing R functions in support of facilitating cybersecurity-based tasks. As it turns out, there is a dearth of functions in R that address this need. To that end, I thought I would present a few ideas for your review and consideration to be included in the next version of quickcode.
In the area of security, I asked a basic question. Using R, how easy would it be to extract one or more IP addresses from a vector string which contained a combination of IP addresses and other data content? As it turns out, there are functions in R that can be used to piece together a script for extracting IP address information, but there is not a comprehensive function that can specifically execute against this task.
FUNCTION IDEA Generate an R function that can be easily deployed to extract one or more IP addresses as they exist from a passed vector string.
RECOMMENDED FUNCTION NAME extract_IP
TOTAL NUMBER OF FUNCTIONAL ARGUMENTS 1
FUNCTIONAL SYNTAX extract_IP(input_string)
FUNCTION STRUCTURE
extract_IP <- function(input_string) {
# Match an IP address pattern
ip_pattern <- "\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b"
# Extract all occurrences of IP addresses
extracted_ips <- stringr::str_extract_all(input_string, ip_pattern)
# Deconstruct the list object
extracted_ips <- unlist(extracted_ips)
# Return the extracted IP addresses (or an empty list if not found)
return(extracted_ips)
}
TEST STATUS The function, as defined under the FUNCTION STRUCTURE section of this issue has been tested, yielding accurate results. However, more testing should be conducted to verify both its accuracy and functional utility.
FUNCTION EXAMPLES Example 1:
x = system("ipconfig /all", intern = TRUE)
extract_IP(x)
Example 2 This example demonstrates the separate extraction of an IP address one per vector element:
str1 = c("Two IP addresses were discovered in the scan. One was at 92.234.1.0.", "The other IP was 62.3.45.255.")
extract_IP(str1)
[1] "92.234.1.0" "62.3.45.255"
Example 3: This example demonstrates the extraction of multiple IP addresses from a single vector element:
str2 = "Two IP addresses were discovered in the scan. One was at 92.234.1.0. The other IP was 62.3.45.255."
extract_IP(str2)
[1] "92.234.1.0" "62.3.45.255"