Extract IP Addresses from JSON file using VB.net - vb.net

is there a way to extract only IPv4 from a file in JSON language using VB.net
For example I would like that when I open a JSON file from VB I can filter only IPv4 from this text for example: https://pastebin.com/raw/S7Vnnxqa
& i expect the results like this https://pastebin.com/raw/8L8Ckrwi i founded this website that he offer a tool to do that https://www.toolsvoid.com/extract-ip-addresses/ i put the link here to understand more what i mean but i don't want to use an external tool i want it to be converted from VB directly thanks for your help in advance.

Your "text" is JSON. Load it using the JSON parser of your choice (google VB.NET parse JSON), loop over the matches array and read the IP address from the http.host property of each element.
Here is an example how to do it using the Newtonsoft.Json package (see it working here on DotNetFiddle):
' Assume that the variable myJsonString contains the original string
Dim myJObject = JObject.Parse(myJsonString)
For Each match In myJObject("matches")
Console.WriteLine(match("http")("host"))
Next
Output:
62.176.84.198
197.214.169.59
46.234.76.75
122.136.141.67
219.73.94.83
2402:800:621b:33f1:d1e3:5544:4fcf:526e
178.136.75.125
188.167.212.252
...
If you want to extract only IPv4 and not IPv6, you can use a regular expression to check whether it matches:
Dim IPV4Regex = New Regex("^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$")
Dim ip = match("http")("host")
If IPV4Regex.Match(ip).Success Then
Console.WriteLine(ip)
End If
62.176.84.198
197.214.169.59
46.234.76.75
122.136.141.67
219.73.94.83
178.136.75.125
188.167.212.252
...
Of course it's always recommended to parse the input data in a structured way, to avoid surprises such as false positives. But if you just want to match anything that looks like an IP address, regardless of the input format (even if you just put hello1.2.3.4world in the textbox), then you could use just the regular expression and skip the structured approach (see it working here on DotNetFiddle):
Dim IPV4RegexWithWordBoundary = New Regex("\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
Dim match = IPV4RegexWithWordBoundary.Match(myJsonString)
Do While match.Success
Console.WriteLine(match.Value)
match = match.NextMatch()
Loop
Here I modified the regular expression to use \b...\b instead of ^...$ so that it matches word boundaries instead of start/end of string. Note however that now we get IP addresses twice with the input that you provided, because the addresses exist more than once:
62.176.84.198
62.176.84.198
197.214.169.59
197.214.169.59
46.234.76.75
46.234.76.75
...

Related

How to deal with arrays in the QuickMap function in Flowgear

I need to match one field called defaultAddress in NetSuite into several fields (Address1, city, State, PostCode and Country) in Autotask.
IIF(ISEMPTY({defaultAddress}), "No Address is provided",SPLIT(REPLACE({defaultAddress}, "", ","), ","))
I have used several Quickmap functions and I have successfully split the original default address into an array. But I can't use array[index] to get a certain part.
Is there a better way that I can split the address and match it with the corresponding fields?
Thanks
Quickmap is backed by VB script, so the way to use indexing is (0) instead of [0] for C#.
You can use:
IIF(ISEMPTY({defaultAddress}), "No Address is provided",SPLIT({defaultAddress}, ","))(0)
IIF(ISEMPTY({defaultAddress}), "No Address is provided",SPLIT({defaultAddress}, ","))(1)
You can see a simple example here: https://flowgear.me/s/b4Dngzi

Lotus Notes Script

I need to have a script which can copy the value from InternetAddress Field in the person document one by one in names.nsf and append it in the User Name field. Can someone help with a working script?
This can literally be done with a one-line formula, using a simple assignment statement and the list append operator. It is really the most basic thing you can do in all of Lotus Notes programming. It doesn't even need to use any of the #functions.
The syntax for an assignment is:
FIELD fieldThatYouWantToSet := value;
The syntax for the list append operator is:
value1 : value2;
The only other thing you need to know is that value1 and value2 can simply be the names of existing items (a.k.a. fields), and the list of values in the second item will be appended to the list of values in the first item.
Then, all you will need to do is to put this one-liner into a formula agent that runs against all documents in the current view, and run the agent from the Actions menu while you are in the view.
Option-1:
There are a few ways to accomplish this, the simplest being , as the user specified before, a simple field function would do.
FIELD UserName := UserNAme:InternetAddress;
You could set and run the above field function in an agent in $UsersView
In option-2, you could also use the "UnProcessedDoc" feature and set and run as an agent.
But, here, I have written one another way to set and run as an agent in $UsersView.
Hope this helps, please approve this answer if this had helped anyone.
Option:2
At present , no Domino in my System, in order to test this snippet. I wish there exists any method online to test this snippet before I post.
But, logically, consider this snippet as a pseudo-code to accomplish ur objective.
Above all, it has been more than a decade or two ever since I have programmed in Domino. Because, I moved on to RDMS, DW, BI and now to Cloud... well Cloud-9. :)
Here is a portion of lotus script code to copy the value from InternetAddress Field in the person document one by one in names.nsf and append it in the UserName field.
Dim db As New NotesDatabase( "Names Db", "names.nsf" )
Dim view As NotesView
Dim doc As NotesDocument
Dim InternetAddress_value As Variant
Set view = db.GetView( "$Users" )
// loop thru all docs in $Users view.
// Get InternetAddress_value and rep it in UserName
Set doc = view.GetFirstDocument
If doc.HasItem("InternetAddress") Then
While Not(doc Is Nothing)
// in this line we concatenate username with IAaddress_value
new_value= doc.GetItemValue( "username" ) + doc.GetItemValue( "InternetAddress" )
Call doc.ReplaceItemValue( "UserName", new_value)
Call doc.Save( False, True )
Set doc = view.GetNextDocument(doc)
Wend
End If
This solution is posted by Mangai#Notes#Domino#Now_HCL . Encourage to post more solutions by approving the answer.

How to create a correct filter string with OR and AND operators for django?

My app has a frontend on vue.js and backend on django rest framework. I need to do a filter string on vue which should do something like this:
((status=closed) | (status=canceled)) & (priority=middle)
but got an error as a response
["Invalid querystring operator. Matched: ') & '."]
After encoding my string looks like this:
?filters=((status%3D%D0%97%D0%B0%D0%BA%D1%80%D1%8B%D1%82)%20%7C%20(status%3D%D0%9E%D1%82%D0%BA%D0%BB%D0%BE%D0%BD%D0%B5%D0%BD))%20%26%20(priority%3D%D0%A1%D1%80%D0%B5%D0%B4%D0%BD%D0%B8%D0%B9)
which corresponds to
?filters=((status=closed)|(status=canceled))&(priority=middle)
How should look a correct filter string for django?
I have no problem if statement includes only | or only &. For example filter string like this one works perfect:
?filters=(status%3D%D0%97%D0%B0%D0%BA%D1%80%D1%8B%D1%82)%20%7C%20(status%3D%D0%9E%D1%82%D0%BA%D0%BB%D0%BE%D0%BD%D0%B5%D0%BD)
a.k.a. ?filters=(status=closed)|(status=canceled). But if i add an & after it and additional brackets to specify the order of conditions calculation it fails with an error.
I also tried to reduce usage of brackets and had string like this (as experiment):
?filters=(status%3D%D0%97%D0%B0%D0%BA%D1%80%D1%8B%D1%82%20%7C%20status%3D%D0%9E%D1%82%D0%BA%D0%BB%D0%BE%D0%BD%D0%B5%D0%BD)
a.k.a. ?filters=(status=closed | status=canceled). This one doesn't work - get neither error nor the data.
I need to have a mixed results in my case: both statuses (closed and canceled) and priority=middle, but a string format isn't correct. Please explain, which format would be Ok?
That doesn't look like a very uri friendly syntax you're trying to use there.
Try doing this instead:
?status[]=closed&status[]=cancelled&priority=middle
Then use request.GET.getlist('status[]') to get back the list and use the values for logical OR queryset filtering:
qs = qs.filter(status__in=request.GET.getlist('status[]', [])
and then add any additional filtering which works as logical AND.
If you're using axios, it should automatically format js status url param into proper format.

How to use Substring in SSIS

I want to export data from SharePoint list to SQL using SSIS.
In SharePoint list, i have a column as multi select, So i am getting below value in my column
1;#control 1;#3;#control 3
I want to use substring in derived column in such a way that i should get below result
1,3
I want only ID from the given column.
I have tried below code
SUBSTRING(ColumnName,1,FINDSTRING(ColumnName,";#",1) - 1)
But it only gives me answer as
1
Can anyone please help me out.?
Because there is an unknown number of controls selected in your SharePoint Multi-Select, a Derived Column transformation is not going to work for you. You'll have to use a script.
One way to parse your string is with regular expressions. You'll have to add an output to the script transformation and assign your parsed string to that output.
Regex controlExpression = new Regex(#"control ([0-9]+)");
MatchCollection controlMatches = controlExpression.Matches(--YOUR INPUT HERE--);
String output = string.Join(",",
(controlMatches.Cast<Match>().Select(n => n.Groups[1].ToString())).ToArray());

Free tool for text document creation with conditions

I was assigned as a tester to create test data in this format
--|id(13603644000102161)|hrtime(2013-02-09T00:00:00.010+0100)-- 
Event-Timestamp=1360364400,                                    
NAS-Port Id=L2TP LNS 204639, 
Service-Type=Framed-User, 
NAS-Identifier=ba2-stlns-67, 
Tunnel-Server-Auth-Id= ba2-stlns-67, 
Tunnel-Type=L2TP, 
NAS-Port-Type=Virtual, 
Tunnel-Client-Endpoint= xxx.81.232.209, 
Acct-Session Id=FF10FFFF58031F5F-50FE2ADA, 
User-Name=uid#edunet.sk, NAS-Port=1862066337, 
Acct-Session-Time=1529998, 
Tunnel-Medium-Type=IPv4, 
Acct-Input-Octets=-277291554, 
Acct-Authentic=Radius, 
Tunnel-Client-Auth-Id= edunet, 
Framed-IP-Address=172.16.0.78, 
Acct-Status-Type=Interim-Update, 
Framed-IP-Netmask=255.255.255.255, 
Framed-Protocol=PPP, 
Calling-Station-Id=#/108778489/BB_WOLK-12 atm 1/1/09/60:1.32, 
Framed-Route=192.168.9.60/30 172.16.0.78, 
Acct-Output-Packets=66401591, 
NAS-IP-Address=213.81.255.165, 
Tunnel-Server-Endpoint= 87.197.192.235
For each of these attributes i have some condition which must be fullfiled. I am looking for a tool where can i enter regex or another condition and it will generate something like this...
Yes... it should be relative easy to code this in java but i have aprx. 50 types of log formats to consider.
to generate text from a regex, see:
http://code.google.com/p/xeger/
Generate a String that matches a RegEx in Python
Reversing a regular expression in Python
java use Regular Expressions to generate a string
Random Text generator based on regex
Generate a random string based on a regular expression