Search a nested dictonary - dictionary

I have a nested dictionary containing locations, equipment, and IP addresses. I want to prompt users to search locations to retreive the IP addresses of that locations. I cannot get the if/else statement to work. I get a keyerror if I mistype or type a nonexistent key. I am obviously a beginner in Python, and I am hoping for some best practices in this case.
`xray = {
"Site1":{"xray1": "10.235.142.128"},
"Site2":{"xray1": "10.41.128.68"},
"Site3":{"xray1": "10.235.103.128", "xray2": "10.235.103.192", "xray3": "10.235.103.191"},
}
search = input('Name of site: ').title().strip()
result = (xray[search])
if search in xray:
for k in result:
print(f"{search} har: {k} - IP {result[k]}")
else:
print(' Location not in list')`

Related

Trouble getting a SPARQL query using a URI

I'm having trouble acquiring instances from a subclass on Protege using SPARQL. The task is to create an ontology using information from a Website. To start this I have tried to get the contact information such as the Email addresses and Phone Numbers. I have provided screenshots of the Classes and Individual Tabs below:
Classes:
Individuals:
I want it to display a list of the two email addresses. I heard there was a way to get them using the URI.
How do I get the URI and how do I enter it after the rdf:type in the query's code?
As you can see in your screenshot, the URI of the 'Contact Email' class is http://www.semanticweb.org/cthom/ontologies/2021/untitled-ontology-34#Contact_Email. So, to get all instances of this class, you can use the following SPARQL query:
select ?contactEmail
where { ?contactEmail a <http://www.semanticweb.org/cthom/ontologies/2021/untitled-ontology-34#Contact_Email> }
Tip: try one of the online SPARQL tutorials to get a bit more familiar with the language.

Using KQL to search on subnets

I want to search something for IP's coming from a specific set of subnets. Some query languages are smart enough to know a /24 is a subnet, but KQL is not. Is there an alternative to this? This is not what I'll be searching on, but for the sake of example let's say you want to search on SignIn logs but only from machines in the 192.168.1.0/24
Please check:
https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/ipv4-is-matchfunction
datatable (ip:string)
[
'192.168.1.64', // match
'192.168.2.11', // no match
]
| where ipv4_is_match(ip, '192.168.1.0/24')

Java API to query CommonCrawl to populate Digital Object Identifier (DOI) Database

I am attempting to create a database of Digital Object Identifier (DOI) found on the internet.
By manually searching the CommonCrawl Index Server manually I have obtained some promising results.
However I wish to develop a programmatic solution.
This may result in my process only requiring to read the index files and not the underlying WARC data files.
The manual steps I wish to automate are these:-
1). for each CommonCrawl Currently available index collection(s):
2). I search ... "Search a url in this collection: (Wildcards -- Prefix: http://example.com/* Domain: *.example.com) " e.g. link.springer.com/*
3). this returns almost 6MB of json data that contains approx 22K unique DOIs.
How can I browse all available CommonCrawl indexes instead of searching for specific URLs?
From reading the API documentation for CommonCrawl I cannot see how I can browse all the indexes to extract all DOIs for all domains.
UPDATE
I found this example java code https://github.com/Smerity/cc-warc-examples/blob/master/src/org/commoncrawl/examples/S3ReaderTest.java
that shows how to access a common crawl dataset.
However when I run it I receive this exception
"main" org.jets3t.service.S3ServiceException: Service Error Message. -- ResponseCode: 404, ResponseStatus: Not Found, XML Error Message: <?xml version="1.0" encoding="UTF-8"?><Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>common-crawl/crawl-data/CC-MAIN-2016-26/segments/1466783399106.96/warc/CC-MAIN-20160624154959-00160-ip-10-164-35-72.ec2.internal.warc.gz</Key><RequestId>1FEFC14E80D871DE</RequestId><HostId>yfmhUAwkdNeGpYPWZHakSyb5rdtrlSMjuT5tVW/Pfu440jvufLuuTBPC25vIPDr4Cd5x4ruSCHQ=</HostId></Error>
In fact every file I try to read results in the same error. Why is that?
what is the correct common crawl uri's for their datasets?
The data set location has changed since more than one year, see announcement. However, many examples and libraries still contain the old pointers. You can access the index files for all crawls back to 2013 on s3://commoncrawl/cc-index/collections/CC-MAIN-YYYY-WW/indexes/cdx-00xxx.gz - replace YYYY-WW with year and week of the crawle and expand xxx to 000-299 to get all 300 index parts. New crawl data is announced on the Common Crawl group, or read more about how to access the data.
To get the example code to work replace lines 24 and 25 with:
String fn = "crawl-data/CC-MAIN-2013-48/segments/1386163035819/warc/CC-MAIN-20131204131715-00000-ip-10-33-133-15.ec2.internal.warc.gz";
S3Object f = s3s.getObject("commoncrawl", fn, null, null, null, null, null, null);
Also note that the commoncrawl group have an updated example.

Four Square API use of section in query in R

Defining x, y, and z as "10013","XXXX","20170104" and using
w <- paste("https://api.foursquare.com/v2/venues/search?near=",x,"&section='food'&oauth_token=",y,"&v=",z,sep="")
u <- getURL(w)
test <- RJSONIO::fromJSON(u)
does not return a good result, but if I replace section='food' with query='food' it will search for food in the name of the location
(I replaced the authorization token with XXXX here).
The venues/search endpoint you're using doesn't have a section parameter. The section parameter is valid with the venues/explore endpoint if that's what you mean to be trying -> https://api.foursquare.com/v2/venues/explore
Note that /search and /explore are designed to accomplish very different things and you should read the docs before you just switch over.
/explore should be used to return recommended venues near a location. (example: coffee shop)
/search should be used to return a specific venue or venues near a location. (example: Starbucks)

Biztalk - can I change the receive port of an existing receive location?

I have two different receive ports and two receive locations - one location assigned to each port. The ports are set to receive the exact same type of file - I ended up with both because I consolidated two different applications that did the same thing.
I want to combine both locations into a single receive port, but I don't seem to be able to change the location that either belongs to - there's no option to do this that I can find. Essentially, I just want to take one location (either - I don't care), and assign it to the other port, so that one port has two locations and the other has none.
Does somebody know of a way to change the receive port of an existing location?
I resorted to the dark side, and updated the SQL table manually. I'd still welcome anybody who has a legitimate, supported way to do this, but to any others who need an answer, here's the script I wrote to fix this problem (no side-effects so far, though it's only been a day):
DECLARE #AppName VARCHAR(255),
#ReceiveLocationName VARCHAR(255),
#NewReceivePortName VARCHAR(255)
SET #AppName = 'Your application name'
SET #ReceiveLocationName = 'Name of your existing receive location'
SET #NewReceivePortName = 'Name of receive port to move location to'
DECLARE #NewPortID INT
DECLARE #ReceiveLocationID INT
SELECT #NewPortID = rp.[nID]
FROM [BizTalkMgmtDb].[dbo].[bts_application] a
JOIN [BizTalkMgmtDb].[dbo].[bts_receiveport] rp
ON a.nID = rp.nApplicationID
WHERE a.nvcName = #AppName
AND rp.nvcName = #NewReceivePortName
SELECT #ReceiveLocationID = Id
FROM [BizTalkMgmtDb].[dbo].[adm_receivelocation]
WHERE Name = #ReceiveLocationName
UPDATE [BizTalkMgmtDb].[dbo].[adm_receivelocation]
SET ReceivePortId = #NewPortID,
IsPrimary = 0
WHERE Id = #ReceiveLocationID
Please do not attempt such direct SQL changes in BizTalk system databases. You always use the API's provided by Microsoft.
Try either the ExplorerOM or WMI to do any such configuration changes.
http://msdn.microsoft.com/en-us/library/microsoft.biztalk.explorerom.receiveport_members(v=bts.10)
http://msdn.microsoft.com/en-us/library/ee277482(v=bts.10).aspx
If in case you make direct DB changes and raise Microsoft support, they won't support it.

Resources