Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string problem
#5
(Aug-04-2020, 04:36 PM)Axel_Erfurt Wrote: x = {'host': 'xxx.xx.xxx.x', 'protocol': 'tcp', 'portid': '1', 'state': 'filtered', 'reason': 'no-response'}
 
print(f"host: {x['host']}\nprotocol: {x['protocol']}\nportid: {x['portid']}\nstate: {x['state']}")

Hello Axel
It's a good idea but in reality X is a string and not a dictionary and I can't seem to change it.
your idea fonction but with dictionary.
Excuse me I don't mention this

(Aug-05-2020, 04:23 AM)buran Wrote: your x looks like poorly formatted json - i.e. you have opening [ and {, but not closing them. Also you use " around the key "xxx.xx.xxx.x" and your string is enclosed in "", i.e. sample x will raise error anyway.
post actual value of x (i.e. I am asking for properly formatted example, not "real" values).

then, if I am right - you can use json to parse it or maybe ast.literal_eval

Thank you for your reponse buran but the key enclosed in "" is the spelling of Nmap fonction .
X is an part of a Nmap tram
the full tram is:
but I can suppr {"172.217.23.131": [
x = {"172.217.23.131": [{'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '1', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'tcpmux', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '2', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'compressnet', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '3', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'compressnet', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '4', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '5', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'rje', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '6', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '7', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'echo', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '8', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '9', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'discard', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '10', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf':'3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '11', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'systat', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '12', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '13', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl':'0', 'service': {'name': 'daytime', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '14', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '15', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl':'0', 'service': {'name': 'netstat', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '16', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'unknown', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '17', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl':'0', 'service': {'name': 'qotd', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '18', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'msp', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '19', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'chargen', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '20', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'ftp-data', 'method': 'table', 'conf': '3'}},{'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '21', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'ftp', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '22', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'ssh', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '23', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'telnet', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '24', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'priv-mail', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '25', 'state': 'open', 'reason': 'syn-ack', 'reason_ttl': '0', 'service': {'name': 'smtp', 'method': 'table', 'conf': '3'}}, {'host': '172.217.23.131', 'protocol': 'tcp', 'portid': '26', 'state': 'filtered', 'reason': 'no-response', 'reason_ttl': '0', 'service': {'name': 'rsftp', 'method': 'table', 'conf': '3'}}]}
Reply


Messages In This Thread
string problem - by Mathisdlg - Aug-04-2020, 03:32 PM
RE: string problem - by Axel_Erfurt - Aug-04-2020, 04:36 PM
RE: string problem - by Donovan - Aug-05-2020, 01:59 AM
RE: string problem - by buran - Aug-05-2020, 04:23 AM
RE: string problem - by Mathisdlg - Aug-05-2020, 08:45 AM
RE: string problem - by buran - Aug-05-2020, 09:18 AM
RE: string problem - by Mathisdlg - Aug-05-2020, 09:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Convert string to float problem vasik006 8 3,445 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  f string concatenation problem growSeb 3 2,287 Jun-28-2021, 05:00 AM
Last Post: buran
Question Problem with string and \n Falassion 6 2,720 Jun-15-2021, 03:59 PM
Last Post: Falassion
  how to deal with problem of converting string to int usthbstar 1 1,992 Jan-05-2021, 01:33 PM
Last Post: perfringo
  Unicode string index problem luoheng 6 3,073 Nov-23-2019, 03:04 PM
Last Post: luoheng
  simple string & input problem kungshamji 5 3,695 Jun-23-2019, 03:54 PM
Last Post: kungshamji
  Problem with inserting a string in to Sqlite db darktitan 3 4,536 Mar-03-2019, 06:30 PM
Last Post: stranac
  IP string manipulation problem TheRealNoob 12 7,367 Feb-04-2019, 09:29 AM
Last Post: perfringo
  problem in replace string into file Saeid_Bibak 1 2,089 Jan-20-2019, 09:46 PM
Last Post: Gribouillis
  String slicing problem Ollew 4 2,827 Sep-08-2018, 08:07 PM
Last Post: Ollew

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020